I am trying to run a fire-and-forget task - IOmniTaskControl.Unobserved works well enough with either IOmniTaskControl.Run or IOmniTaskControl.Schedule(IOmniThreadPool), but the IOmniTaskControl object is never destroyed.
I am limited to using Unobserved since I have an arbitrary number of tasks and I do not want to store them in a dedicated variable or a list - removing a task from that list would be a hustle in itself since it can only be done from the task body.
Am I missing something? I thought that IOmniTaskControl.Unobserved will destroy itself after it runs.
I think I've never answered my own question that quickly :-)
TOmniTaskControlis destructed from theTOmniEventMonitor.WndProcwindow proc, which of course only runs if there is a message loop in the thread where the monitor was created by the task. In my case, the tasks were created from a dedicated thread (I usedTThread.CreateAnonymousThread). Adding a message loop to my thread proc (which runs an infinite while loop) fixed the problem: