I have an implementation question centered around queuing long-running tasks that return a value. Because of the CPU usage in this task, I want to limit the number of tasks running at the same time to a constant number.
I'm returning an async task to the caller that it will await on, and hopefully the implementation will still let that happen.
This is the task that I would like to queue, and let the caller wait on:
public async Task<string> LongTask(string filename)
{
return await Task.Run(() =>
{
//does something for awhile
return "my result";
});
}
This is how it is called from the caller, which will wait on the result:
string result = await LongTask("test");
Thanks in advance.