John Livermore
John Livermore

Reputation: 31313

cleanup after completion of a .NET Task

I have the following code that processes an INotification (custom interface)

var mgr = new NotificationManager();
var task = new Task(() => mgr.Send(notification));
task.Start();

Problem is once the Task completes, I need to perform some cleanup on notification. What is the approach for doing this with the Task Parallel library?

Upvotes: 1

Views: 325

Answers (2)

Allon Guralnek
Allon Guralnek

Reputation: 16121

You can provide a multi-statement lambda:

Task.Factory.StartNew(() => { mgr.Send(notification); Cleanup(); };

Upvotes: 4

MBen
MBen

Reputation: 3996

You can do this using ContinueWith. Here is the documentation ContinueWith

Upvotes: 4

Related Questions