B
Bruce
Hi
I have a question on handling Dispose() in an application I wrote.
When I get a signal to stop the application, I have a central class
that disposes all the other classes to release native resources.
Since there are callback methods in the classes, If I have a class A
that has IDisposable implemented, when Dispose is called, any of the
other methods in A could be executing and end up throwing weird
exceptions
How to handle these scenarios gracefully? I thought of 2 options
1. Have a inDisposing flag on the class that is set when Dispose()
gets called. In every method, catch all exceptions, rethrow them if
inDisposing is false. Swallow them otherwise.
2. In every method, lock a disposeLock object, check if disposed flag
is true, if not do the work and release it at the end. Dispose() also
tries to get hold of the lock before disposing.
I am not sure what is the recommended way of handling exceptions that
occur in different threads because of calling Dispose.
Thanks
Bruce
I have a question on handling Dispose() in an application I wrote.
When I get a signal to stop the application, I have a central class
that disposes all the other classes to release native resources.
Since there are callback methods in the classes, If I have a class A
that has IDisposable implemented, when Dispose is called, any of the
other methods in A could be executing and end up throwing weird
exceptions
How to handle these scenarios gracefully? I thought of 2 options
1. Have a inDisposing flag on the class that is set when Dispose()
gets called. In every method, catch all exceptions, rethrow them if
inDisposing is false. Swallow them otherwise.
2. In every method, lock a disposeLock object, check if disposed flag
is true, if not do the work and release it at the end. Dispose() also
tries to get hold of the lock before disposing.
I am not sure what is the recommended way of handling exceptions that
occur in different threads because of calling Dispose.
Thanks
Bruce