2

I need to create a scheduled task. For that I'm trying to learn how to do that, and am currently thinking of using TaskSchedulerClass from TaskScheduler Class Library. I got a code examples here (and there's another one I might try here). But - I don't want to actually run it without making sure I know how to cancel it when needed.

So my question is: How do I cancel such a task-registration in code?

(Just "Try it!" won't suffice in this case. Because the point is I don't want to get stuck with something I can't stop.)

Community
  • 1
  • 1
ispiro
  • 26,556
  • 38
  • 136
  • 291

1 Answers1

2

What about TryDequeue Method?

It's attempts to dequeue a Task that was previously queued to this scheduler.

You need to use the same Task you sent to QueueTask function.

If you don't have the instance of this Task you can try and retrieve it using GetScheduledTasks, but it stated it in use For debugger support only

Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
  • Thanks. (It took me some time, until I figured out that Intellisense doesn't show it, and that I have to add the whole namespace before it...) Anyway, how do I find the task? I assume I can't just create a new task and cancel it. – ispiro Jul 08 '12 at 15:12
  • But I'll want to cancel it in a separate run of my code. Will it not simply create a _new_ task and cancel _that_? – ispiro Jul 08 '12 at 15:22
  • Right. That's why I removed it from my comment. So am still looking for a solution. – ispiro Jul 08 '12 at 15:33
  • I'm getting "... TaskScheduler.TryDequeue...is inaccessible due to its protection level". Any ideas? – ispiro Jul 08 '12 at 15:50
  • I'm accepting this answer for lack of a better one. But I'm still interested in an answer. – ispiro Jul 16 '12 at 12:49