A continuation of a question asked here :
In the aforementioned question I have the following function which returns an object of type Task (for incremental testing purposes) :
private static Task<object> GetInstance( ) {
return new Task<object>( (Func<Task<object>>)(async ( ) => {
await SimpleMessage.ShowAsync( "TEST" );
return new object( );
} ) );
}
When I call await GetInstance( );
, the function is called (and I assume the task is returned since no exception is thrown) but then the task just sits there.
I can only guess I am doing this wrong then.
I do not want this function to return a task that is already running ( that is IMPERATIVE ).
How do I asynchronously run the task returned by this function?
await
ing onGetInstance
, and that's why your method waits there. It's still an async call, as the thread can be released for that wait. I think you're mixing asynchronous execution with multitasking.GetInstance()
at that point in time? Perhaps you want something likeFunc<Task<object>>
orLazy<Task<object>>
so you may defer the call toGetInstance()
.Task
which will complete at some point in time without being explicitly started. I would maintainFunc
instances to create the tasks as and when required.