In fact, a brand new feature does allow this. Try the following:
private TaskEventWatcher watcher;
// Create and configure a new task watcher for the task folder
private void SetupWatcher(Task task)
{
if (task != null)
{
// Set up a watch over the supplied task.
watcher = new TaskEventWatcher(task);
// Assign a SynchronizingObject to a local UI class to synchronize the events in this thread.
watcher.SynchronizingObject = this;
// Only watch for task events that indicate success (102), failure (103), or termination (111)
watcher.Filter.EventIds = new int[] { 102, 103, 111 };
// Assign an event handler for when events are recorded
watcher.EventRecorded += Watcher_EventRecorded;
// Start watching the task by enabling the watcher
watcher.Enabled = true;
}
}
// Cleanup and release the task watcher
private void TearDownWatcher()
{
if (watcher != null)
{
// Unhook the event
watcher.EventRecorded -= Watcher_EventRecorded;
// Stop watching for events
watcher.Enabled = false;
// Initiate garbage collection for the watcher
watcher = null;
}
}
// Do something when task events occur
private void Watcher_EventRecorded(object sender, TaskEventArgs e)
{
DoSomething(e.TaskName);
}