From my desktop UI I need to make a call to a web service (a long running operation). Let's say the API returns a Boolean value. Now it could take several seconds to receive a response. When I invoke this API I would like the UI to still be responsive.
I've wrapped the call to the API with a Task.Run(). From within this Task.Run action I return the value like this:
Task.FromResult<bool>(result);
The method which contains this Task.Run() has a signature like this:
public async Task<bool> GetStatus();
Now when I run all this, it appears to be working. But I am not convinced this is working the way I think it's working.
Can anybody tell me if my explanation here is correct?
- The Task.Run() allows its contents to run asynchronously.
- The method which contains Task.Run() will return immediately.
- When the async Task is completed, any code that exists below the Task.Run() line will be executed.