Insider1984
Technical User
Hi there. I'm building an application which spawns a number of threads to do a lot of different simple unit style tasks. While everything seems to be nearly exception free there is a case maybe every couple days of runtime that something throws an exception. The problem is that the architecture is so "flexible" and isolated that the threads pumping data into the queue's doesn't know the working thread died.
These obviously leads to a lot of issues which is why I need a way for the application which "supports" these working threads to be aware of anything bad that happens inside of them.
My thought was to have some sort of "Keep Alive" signal triggered within the thread every "X" number of seconds to show it's still alive at a base thread level. The main application would then monitor all the threads to ensure that it received a "signal" from all tools.
I'm pretty weak in events which is where I need the help.
I understand that I'll have a AutoResetEvent in each "workerthread" and that my main application will subscribe to all events and perform a "WaitAll" on an Array of the events. Finally the private autoreset event would need to be triggered by the workthread every X seconds which may involve it's own timer based event.
What I'm having trouble wrapping my head around is how I can correctly trigger the AutoResetEvent every X seconds and ensure that I'm doing this on a thread which itself has WaitHandles on it's incoming data queue's.
What I know doesn't work is triggering the event from another thread because the event will still trigger even if the worker thread has died. The kink in this whole ordeal is that I need knowledge of a thread's death quicker than it's possibility of getting data to process. (Which is anywhere from <1ms to >1 minute.
=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET
These obviously leads to a lot of issues which is why I need a way for the application which "supports" these working threads to be aware of anything bad that happens inside of them.
My thought was to have some sort of "Keep Alive" signal triggered within the thread every "X" number of seconds to show it's still alive at a base thread level. The main application would then monitor all the threads to ensure that it received a "signal" from all tools.
I'm pretty weak in events which is where I need the help.
I understand that I'll have a AutoResetEvent in each "workerthread" and that my main application will subscribe to all events and perform a "WaitAll" on an Array of the events. Finally the private autoreset event would need to be triggered by the workthread every X seconds which may involve it's own timer based event.
What I'm having trouble wrapping my head around is how I can correctly trigger the AutoResetEvent every X seconds and ensure that I'm doing this on a thread which itself has WaitHandles on it's incoming data queue's.
What I know doesn't work is triggering the event from another thread because the event will still trigger even if the worker thread has died. The kink in this whole ordeal is that I need knowledge of a thread's death quicker than it's possibility of getting data to process. (Which is anywhere from <1ms to >1 minute.
=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET