简体   繁体   中英

how can I set a breakpoint to get the async result in this scenario?

How can I set a breakpoint to get the async result in this scenario?

static void Main(string[] args)
{
    Test().GetAwaiter().GetResult();
}

static async Task Test()
{
    await GetAllUsers();
}

static async Task GetAllUsers()
{
    using (var client = GetHttpClient())
    {
        var response = client.GetAsync(baseUrl + "api/v1/users");
    }
}

If I set a breakpoint at the end of the using statement in GetAllUsers() then the response value is:

Id = 1, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"

When I continue to step through the code I'm not clear on how I can get a handle to the final value. Any suggestions on the code I can include to get a handle to the final return value?

You are missing await keyword near GetAsync function call. After fixing that, you will be able to see the result. (BP at end of using )

static async Task GetAllUsers()
{
    using (var client = GetHttpClient())
    {
        var response = await client.GetAsync(baseUrl + "api/v1/users");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM