Monitor.Exit ArgumentException

  • Thread starter Thread starter MDB
  • Start date Start date
M

MDB

Hello all, I am getting an ArgumentException error when I call this code.
Anyone know why, I am new to the monitor class and don't have a clue what is
causing this. I get the error when I call Monitor.Exit.


Monitor.Enter(myApp.Classes.Globals.gobjCopyDB);
myApp.Classes.Globals.gobjCopyDB = true;
Monitor.Exit(myApp.Classes.Globals.gobjCopyDB);


TIA
 
Because you are calling exit on a different monitor/object than you
entered on.

Your sample show that gobjCopyDB is a boolean, which would get
temporarily boxed when you use it with Monitor.Enter. (I'm kind of
surprised the compiler didn't catch that since this will *never* work).
A different temp box will be created in the call to Exit.

Tom
 
Okay, Thanks

TDC said:
Because you are calling exit on a different monitor/object than you
entered on.

Your sample show that gobjCopyDB is a boolean, which would get
temporarily boxed when you use it with Monitor.Enter. (I'm kind of
surprised the compiler didn't catch that since this will *never* work).
A different temp box will be created in the call to Exit.

Tom
 
Back
Top