I've put some code into a background task as following:
private async void WriteToAuditLog(object sender, WriteToAuditLogAction e)
{
var auditTuple = new Tuple<DateTime, string>(e.Time, e.Message);
var backgroundTask = Task.Factory.StartNew(() => { WorkerOperationForWriteToAuditLog(auditTuple); });
await backgroundTask;
***backgroundTask.Dispose();***
}
Is it safe to call dispose on the task after invoking await? As far as I understand, the dispose line will be executed after the task has been completed and the control is returned to the UI thread, right? So, I no longer have need of the task and may safely Dispose it, am I correct?