Task Status WaitingForActivation

14,823

It keeps hanging because the status never leaves WaitingForActivation when I call it.

Actually, the WaitingForActivation is just an indication that the task has not yet completed. It's not the cause of the hang, but an indicator of it. Promise Tasks (including tasks returned by async methods) will stay in the WaitingForActivation state until they complete; I describe the task state machine in more detail on my blog.

The most likely cause of a deadlock is calling Task<T>.Result or Task.Wait further up the stack. I describe this deadlock in full on my blog, but the gist of it is that await will capture a "current context" and use that to resume its async method. If called from the UI thread, then that context is the UI thread, and if the UI thread is blocked by calling Result/Wait, then the async method cannot resume on that UI thread.

Share:
14,823
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin about 2 years

    I have the following function :

    async public Task<bool> checkNetwork (RestClient _client, ConnectivityManager conn)
        {
            var connected = false;
            var activeConn = conn.ActiveNetworkInfo;
            if (activeConn != null && activeConn.IsConnected) {
                var request = new RestRequest ();
                request.Timeout = 5000;
                var response = await _client.ExecuteAwait (request);
                //Task<IRestResponse> tmpResponse = _client.ExecuteAsync (request);
                if (response.ErrorException != null)
                    connected = false;
                else
                    connected = true;
            }
    
            return connected;
        }
    

    It keeps hanging because the status never leaves WaitingForActivation when I call it. Any ideas?