I want to make the calls to a method parallel. In this method I calculate some value (very fast) and write the value of this calculation into a database table.
Therefore I use a Threadpool
ThreadPool.QueueUserWorkItem((state) => {
method();
});
After a while of calculation (not deterministic, the time when this happens varies, sometimes after a few minutes, sometimes after some hours) the Threadpool is full, but not with the thread of method() but with the thread of my mysql class that calls MySqlCommand.ExecuteNonQuery
.
Does anyone have an idea how to avoid this? In the documentation of the mysql classes I found out that you cannot terminate an executing query but how to avoid such problems?