Hi all,
Just wondering if there is a "standard" to handle the following situation.
I have a GUI which calls SQL queries in another thread. These queries can run for a long time and possibly time out. The problem I have is that when there is an exception the whole app crashes (as the exception isnt being handled in the new thread). Now it's fairly simple to correct this issue, however I want the user (i.e. GUI) to be notified of the error and display it to the users.
Now to my knowledge there are a few options:
My idea situation would be one where the worker thread could put the exception on the main thread before exiting, however I dont think this exists (exceptions are stack-bound objects. Since every thread has its
own stack, an exception thrown in thread A cannot suddenly appear in
thread B).
So whats the best option here? Just to be clear I know how to handle this situation but not the *best* way.
Thanks in advance!
Just wondering if there is a "standard" to handle the following situation.
I have a GUI which calls SQL queries in another thread. These queries can run for a long time and possibly time out. The problem I have is that when there is an exception the whole app crashes (as the exception isnt being handled in the new thread). Now it's fairly simple to correct this issue, however I want the user (i.e. GUI) to be notified of the error and display it to the users.
Now to my knowledge there are a few options:
- Events - The event would return the result and also some args to specify the state etc (complete, cancelled, error).
- Async Delegates - This is my current implementation and just returns the result. To make this handle errors correctly, I would need to wrap the result and any error information into a "bigger" class.
- Polling - The "worker" thread could actually not terminate and the "main" thread could just poll states on the worker thread to see if it has a result and if not check for state.
My idea situation would be one where the worker thread could put the exception on the main thread before exiting, however I dont think this exists (exceptions are stack-bound objects. Since every thread has its
own stack, an exception thrown in thread A cannot suddenly appear in
thread B).
So whats the best option here? Just to be clear I know how to handle this situation but not the *best* way.
Thanks in advance!