tag:blogger.com,1999:blog-5359546512544809971.post3524576100735387830..comments2024-03-29T00:46:49.972-07:00Comments on Jeremy Bytes: UI Considerations When Using Asynchronous MethodsJeremyhttp://www.blogger.com/profile/06749690234470413216noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-5359546512544809971.post-58769001894851655592016-11-03T04:20:09.463-07:002016-11-03T04:20:09.463-07:00Hi Brady. In this example, the CancellationTokenSo...Hi Brady. In this example, the CancellationTokenSource is a class-level variable. So it is accessible by both the method that calls the asynchronous method (the "Fetch" button) and also by the method that sets the token to the canceled state (the "Cancel" button). Details are in this article: https://jeremybytes.blogspot.com/2015/01/task-and-await-basic-cancellation.html<br /><br />This particular example is a bit unrealistic (since we have 2 separate calls to the same method that can cancel it), but normally we would keep a reference to our token source in the calling code so that we can set the canceled state when appropriate.<br />-JeremyJeremyhttps://www.blogger.com/profile/06749690234470413216noreply@blogger.comtag:blogger.com,1999:blog-5359546512544809971.post-36391342029481304672016-11-02T21:58:51.407-07:002016-11-02T21:58:51.407-07:00How do you expect to set a cancellation on the tok...How do you expect to set a cancellation on the token source if that is only a local variable inside the event handling code you want to cancel?Brady Kellyhttps://www.blogger.com/profile/01045877177605836930noreply@blogger.comtag:blogger.com,1999:blog-5359546512544809971.post-15287879366315567812014-12-30T12:09:49.201-08:002014-12-30T12:09:49.201-08:00Thanks for the tip, Alois. That's definitely a...Thanks for the tip, Alois. That's definitely a better approach. I'll update the code and drop a note in the article.<br />-JeremyJeremyhttps://www.blogger.com/profile/06749690234470413216noreply@blogger.comtag:blogger.com,1999:blog-5359546512544809971.post-83588879843110018812014-12-30T11:27:44.085-08:002014-12-30T11:27:44.085-08:00Nice article. For the Task based continuation expe...Nice article. For the Task based continuation expecting a CancellationToken you do not need to create one but you can use CancellationToken.None instead.Alois Kraushttps://www.blogger.com/profile/05066929000823203046noreply@blogger.com