Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need a taskstarted and taskcompleted events to be fired when ever a task is started and completed when using TPL.Is there any way to accomplish this ?
Posted

1 solution

 
Share this answer
 
Comments
Vasudevan Kannan 6-May-12 1:44am    
The links are useful.For a more specific case ,how would you simplify this code below.Can you see the logic for setting and removing the busy indicator is repeated ?

ComponentViewModel.Instance.IsApplicationBusy = true;
ComponentViewModel.Instance.BusyMessage = "Loading...";

var task1 = Task.Factory.StartNew(() => DoTask1());
task1.ContinueWith(antecdent =>
{
ComponentViewModel.Instance.IsApplicationBusy = false;
CustomAction1();
}

Second Instance :

ComponentViewModel.Instance.IsApplicationBusy = true;
ComponentViewModel.Instance.BusyMessage = "Loading...";

var task2 = Task.Factory.StartNew(() => DoTask2());
task2.ContinueWith(antecdent =>
{
ComponentViewModel.Instance.IsApplicationBusy = false;
CustomAction2();
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900