문제

I have a situation where I want to allow a user to type into a WPF TextBox, on each keystroke I call OnPropertyChanged and push to my binding source (using SourceUpdatedTrigger=PropertyChanged) I want there to be a short delay before attempting to process the data (say... 1 second) Think of this like a spell check system where it waits for the user to stop typing before telling them they can't spell.

My issue is:

 await TaskEx.Delay(1000, cts.Token);
 await TaskEx.RunEx(PollAsync, cts.Token);

works fine until you actually cancel, but then the cancelation token source is permanantly in the "cancelation requested" state, and I have to reinstanciate the CTS... this seems... fundamentally wrong... Is there a better way to "reset" the CTS, yet still notify existing tokens that they should cancel?

도움이 되었습니까?

해결책

No, a CancellationTokenSource can only be cancelled once - as you say, you need to create a new one after you've cancelled it, for further tasks.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top