My event will be fired whenever a specific file on my system is modified. The processing done on the file when the event is fired is estimated to be around 10 minutes. I’d like to know if it’s possible to cancel the processing and restart the processing if the file is modified again before the processing for the first modification is done. If so, how can I accomplish this?
Share
It seems to me you don’t want to cancel the event but the handling of the previous event. Assuming that’s the case, you’ll need to make your file-processing code cancellation aware.
I suggest you use a CancellationToken and CancellationTokenSource because they are available in the framework already. When you start handling the event you create a new cancellation token source and save it somewhere, and clear it when you’re done. If you get a new event check whether there’s a saved cts, and request a cancellation if that’s the case.
The link I included contains some code samples on how to write your processing code.