Wednesday, July 30, 2014

How do I create and run an asynchronus method on two different thread?

Hi Lucas,



My observation is you are looking for a way of parallelizing, if that's the case below might help you.




static void SomeProcess()
{
Thread.Sleep(3000); // Do CPU work here.
}

static async Task Test()
{
// Start two background operations.
Task task1 = Task.Run(SomeProcess);
Task task2 = Task.Run(SomeProcess);

// Wait for them both to complete.
await Task.WhenAll(task1, task2);
}






No comments:

Post a Comment