Home How are CancellationToken Transported on Web Requests
Reply: 0

How are CancellationToken Transported on Web Requests

johnny 5
1#
johnny 5 Published in 2017-12-07 19:40:58Z

I'm doing some research on Cancelling Async Requests through WebAPI,

Recently I discovered that latest version of WebApi(not .NET-Core's), supports cancellation tokens. As a test I've written this code.

[HttpGet]
[Route("LongRequest")]
public async Task<string> VeryLongRequest(string Key, CancellationToken token)
{
    for (int i = 0; i < 5; ++i)
    {
        if (false == token.IsCancellationRequested)
        {
            Thread.Sleep(5000);
        }
        else
        {
            Trace.WriteLine("Cancelled");
        }
    }

    return "Complete";
}

This code works, and the cancellation token is updated, when a user closes the window/refreshes/ or navigates to a new page (Not on an SPA).

Being that HTTP Request's are suppose to be stateless, How is the cancellation mapping back to the request?

And how can I Manually Invoke a cancellation from my client?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.341497 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO