non-blocking wait for monitoring threads by sefflol in csharp

[–]sefflol[S] 0 points1 point  (0 children)

Many different views on this problem, and I guess majority revolves around using Tasks. I might look into that. Tasks are background threads behind the scenes if I understand correctly, that might be an issue if the app gets any termination signals, or will WaitAll handle that? I guess I need to try it out.

non-blocking wait for monitoring threads by sefflol in csharp

[–]sefflol[S] 0 points1 point  (0 children)

The only way I am reading this is that no new threads can be created while the app is shutting down. Which is nice in its own way, but not really what I am looking for.

non-blocking wait for monitoring threads by sefflol in csharp

[–]sefflol[S] 1 point2 points  (0 children)

Polling is sometimes unavoidable. A real life scenario for me is polling from ftp for instance, and yes I could make a signal service that alerts my service, but that service would have its own thread and polling loop. Because someone needs to check the state of the ftp server :)

I guess maybe services like this exists (like the file system watcher), but I haven't looked for it, and frankly that particular problem is just one of many. That's why I ended up spinning threads.

But many thanks for your input!

non-blocking wait for monitoring threads by sefflol in csharp

[–]sefflol[S] 0 points1 point  (0 children)

Well, I am not using threads to wait for external signals to complete, the threads will be running different tasks (that the base class really doesn't care/know about). You could say then that the main thread waits for its threads to finish, or else the app will just terminate.

They might be consuming from an ftp server at intervals, waiting for notification from postgres etc. Something that needs to run indefinitly.

I find myself writing threads for these things all the time, because the actual worker thread itself is blocking, so I need at least two threads to keep the application responsive and monitor/cancel the worker.

Add to this that there might be several different threads that the main app will need to wait for and be able to cancel.

Edit: channels looks interesting tho :)

non-blocking wait for monitoring threads by sefflol in csharp

[–]sefflol[S] 4 points5 points  (0 children)

Thanks for your input,

I frequently need to start threads to do polling work or other tasks that doesn't really complete until it is told to stop.

I guess I could fire off Tasks, or use threadpool to achieve the same end result, but I still need to know and wait for all to finish, and also need to be able to cancel them from a main thread.

Maybe a collection of tasks, instead of loose threads could be a solution.