c# - How do you properly dispose of a CancellationTokenSource in a ViewModel? -


typically, when trying asynchronous tasks in view-model, code looks (simplified):

public class myviewmodel {     private cancellationtokensource cts { get; set; }      public async task process()     {         cts = new cancellationtokensource();          try         {             await longrunningtask(cts.token);         } catch (operationcanceledexception) { }     }      public async task cancel()     {         cts.cancel();     } } 

the problem cancellationtokensource idisposable. mean place in using block, or there more since stored in private property?


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -