Task status Pending activation

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 continues to hang because the status never leaves WaitingForActivation when I call it. Any ideas?

+4
source share
1 answer

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

Actually, it WaitingForActivationis only a sign that the task has not yet been completed. This is not a reason to hang, but an indicator of this. Promise tasks (including tasks returned by methods async) will remain in a state WaitingForActivationuntil completion; I describe the state machine of a task in more detail in my blog .

Task<T>.Result Task.Wait . , , await " " async . , , Result/Wait, async .

+11

Source: https://habr.com/ru/post/1548666/


All Articles