T
Travis Parks
Hello:
I have group of independent jobs that I run in parallel using
asynchronous delegates. I am starting each task with code that looks
like this:
Action action = job.Run;
action.BeginInvoke((IAsyncResult result) =>
{
action.EndInvoke(result);
}, null);
I am expecting the call to EndInvoke to throw an exception if one
occurred. This is happening as expected. However, when it does, it
appears that other jobs start throwing exceptions complaining that
database connections are closed. Each job is responsible for creating
a new connection for itself. The jobs do not use any shared data, data
is transferred via a database. So synchronization isn't an issue.
I am wondering how the first exception is triggering the closing/
disposal of the connections in the other threads. Could this have
something to do with connection pooling? I was thinking that maybe the
first exception was killing the main thread, triggering some kind of
resource cleanup on the background threads.
Currently, I am handling this by capturing every exception that is
being thrown, and only throwing the relavent one. I can tell which is
relevant by looking at the type of the exception. The first exception
is a custom exception and all the others are
InvalidOperationExceptions (The Connection must be open...). However,
I would like to avoid the other exceptions entirely, since I don't
think they should be happening.
We are probably a release away from using .NET 4.0. I am wondering
whether I should just use my current technique until I can start using
the TPL.
Is there some underlying mechanism that calls dispose on background
threads? It just seems weird to me that independent jobs would have
this problem. It is even happening when the main thread captures and
swallows these exceptions.
Thanks for any insight. I will try to create a simple example that
reproduces the issue.
Thanks,
Travis Parks
I have group of independent jobs that I run in parallel using
asynchronous delegates. I am starting each task with code that looks
like this:
Action action = job.Run;
action.BeginInvoke((IAsyncResult result) =>
{
action.EndInvoke(result);
}, null);
I am expecting the call to EndInvoke to throw an exception if one
occurred. This is happening as expected. However, when it does, it
appears that other jobs start throwing exceptions complaining that
database connections are closed. Each job is responsible for creating
a new connection for itself. The jobs do not use any shared data, data
is transferred via a database. So synchronization isn't an issue.
I am wondering how the first exception is triggering the closing/
disposal of the connections in the other threads. Could this have
something to do with connection pooling? I was thinking that maybe the
first exception was killing the main thread, triggering some kind of
resource cleanup on the background threads.
Currently, I am handling this by capturing every exception that is
being thrown, and only throwing the relavent one. I can tell which is
relevant by looking at the type of the exception. The first exception
is a custom exception and all the others are
InvalidOperationExceptions (The Connection must be open...). However,
I would like to avoid the other exceptions entirely, since I don't
think they should be happening.
We are probably a release away from using .NET 4.0. I am wondering
whether I should just use my current technique until I can start using
the TPL.
Is there some underlying mechanism that calls dispose on background
threads? It just seems weird to me that independent jobs would have
this problem. It is even happening when the main thread captures and
swallows these exceptions.
Thanks for any insight. I will try to create a simple example that
reproduces the issue.
Thanks,
Travis Parks