Background Process

229
0
11-16-2020 01:00 PM
rlwarford
New Contributor

I have a long running process that I need to parse out to run concurrently on multiple background threads. But I haven't been successful running.

I've been trying it using 'async', 'QueuedTask.Run', 'Enumerable and "await Task.WhenAll(tasks)"' in various combinations, but my code always waits for each process to finish. 

Any suggestions (or an example) would be appreciated.

 

I used Enumerable for one of my tests (but code always stops until Enumerable finishes) :

var tasks = Enumerable.Range(0, 10).Select(i => AsyncTest()).ToList();
await Task.WhenAny(tasks);

 

private async Task<string> AsyncTest()
{

QueuedTask.Run(() =>
{

double increment = 100.0 / Convert.ToDouble(100000000);
for (int i = 0; i < 100000000; i++)
{

int result = Convert.ToInt32(i / 1) + i;
result = Convert.ToInt32(i / 1) + i;
result = Convert.ToInt32(i / 1) + i;
result = Convert.ToInt32(i / 1) + i;

}
});

return "Done";
}

0 Kudos
0 Replies