I have a project recently upgraded from .net 1.1 to .net 4.0. We get an error from the user-defined "ThreadPool" class (yes, someone felt the need to write their own), and now I'm wondering what it could be.
The error is issued from the following code:
private void Submit(WorkItem work) { this.AdjustPoolSize(); lock (this.workQueue.SyncRoot) {
Commented code is how the code was passed to me. Unfortunately, I donβt know much about this project and only here to fix this problem. We see an error:
System.Threading.SynchronizationLockException was unhandled by user code Message=Object synchronization method was called from an unsynchronized block of code. Source=mscorlib StackTrace: at System.Threading.Monitor.ObjPulse(Object obj) at System.Threading.Monitor.Pulse(Object obj) at CustomThreadPoolObject.Submit(WorkItem work) in D:\...\Threading.cs:line 1438 at CustomThreadPoolObject.Submit(WaitCallback callback, Object state) in D:\...\Threading.cs:line 1349 at SomeGroupProcessFunctionality.Submit(PooledThread thread, TaskInfo task, String appServer, Hashtable batchHandleTable) in D:\...\ProcessGroup.cs:line 143 at System.Runtime.Remoting.Messaging.Message.Dispatch(Object target, Boolean fExecuteInContext) at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext) InnerException:
In appearance, something works as βaffordableβ when it really is not. I tried to do this and found http://bbellomo.blogspot.com/2007/03/object-synchronization-method-was.html , but this did not help me since I did not quite understand how its problem and resolution.
Hope someone can give me some advice.
Thanks!
source share