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
Post a Comment