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

Capture and play voice with Asterisk ARI -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -