Implementing a delayed execution task with cancellation

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?

Answers


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.


Need Your Help

concatenate div into scrapped content

php domparser simpledom

I'm using PHP simple dom parser, how should I insert extra entities within them? like $html contain

compile error:A field initializer cannot reference the non-static field, method, or property

c# compiler-errors chess

when i compile the code below the compiler give the error:A field initializer cannot reference the non-static field, method, or property in this code(which have stars)

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.