简体   繁体   中英

How can I add the result of an asynchronous method to the Glimpse Broker?

Title says it all really.

I'd like to put some information about the result of an async method into the Glimpse Message Broker. I tried to use Task.ContinueWith for this:

        task.ContinueWith((t) =>
        {                
            var response = t.Result;
            var message = new ExternalRequestMessage
            {
                Url = url,
                Method = method,
                RequestBody = requestBody,
                WasAsync = true,
                StatusCode = (int)response.StatusCode,
                Status = response.StatusCode.ToString(),
                WasSuccess = response.IsSuccessStatusCode,
                Fault = response.Fault,
            };

            if (messageBroker != null)
            {
                messageBroker.Publish(message);
            }
        });

This code executes without issue, and I can put a breakpoint on and follow the code through so I know it executes.

However, when I come to read the messages back off the broker, they are not there. eg, a breakpoint on the tab code below shows that the messages are not there:

    public override object GetData(ITabContext context)
    {
        return context.GetMessages<ExternalRequestMessage>();
    }

Additionally- I am putting ExternalRequestMessage s onto the broker from a synchronous context, and those messages are showing up in the tab as expected.

Can anyone shed some light on what's going on here?

Edit: I should add that I am using ContinueWith as I don't want the app to wait on the result just to add the message to the broker, so just using task.Result is not an option.

Figured this out-

My web.config file had

<appSettings>
    <add key="Glimpse:DisableAsyncSupport" value="true"/>
</appSettings>

Removing this value or setting it to false resolves the issue.

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