By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

Monitor.Enter

P: 4
Hi,

I just tried to convert my current project to the new beta 2 of the .net
framework and I encountered some problems with my thread synchronization -
that formerly worked well.

System.Threading.SynchronizationLockException: Object synchronization method was called from an unsynchronized block of code.
Code is below

Monitor.Enter (collectionvar );

if ( collectionvar .Count == 0 )
collectionvar = value();

Monitor.Exit (collectionvar );//i am getting error here.

return collectionvar ;
Apr 25 '07 #1
Share this Question
Share on Google+
4 Replies


P: 4
Hi guys,

Waiting for your soluitons.

Thanks in advance
May 10 '07 #2

Motoma
Expert 2.5K+
P: 3,235
I have not done anything with Synchronization, but what may be happening is that your call to Monitor.Enter may be failing. Take a look at the MSDN and see what the possible results for that call are, and perhaps you can catch an error before an exception is thrown.


Hi,

I just tried to convert my current project to the new beta 2 of the .net
framework and I encountered some problems with my thread synchronization -
that formerly worked well.

System.Threading.SynchronizationLockException: Object synchronization method was called from an unsynchronized block of code.
Code is below

Monitor.Enter (collectionvar );

if ( collectionvar .Count == 0 )
collectionvar = value();

Monitor.Exit (collectionvar );//i am getting error here.

return collectionvar ;
May 10 '07 #3

P: 4
I have not done anything with Synchronization, but what may be happening is that your call to Monitor.Enter may be failing. Take a look at the MSDN and see what the possible results for that call are, and perhaps you can catch an error before an exception is thrown.
Thanks Motoma,
Atleast you initiate, I'm just wondering why this code is not working in VS2005 , earliere it was working in VS2003.

I have seen lot discussion on Monitor.enter/exit ...but not one give the what need to do here.
May 11 '07 #4

P: 4
1 first run of code:I got some point here.....what happing here when nothinin in _cache (cach.count=0 )at the time of Monitor.enter.....and after loading value it has some value at Monitor.exit so raising error because object value is not same.

2:second run no error because object have same value.

why this happing in only ASP.NET 2.0



public static GetCountyCollection Cache
{
get
{
Monitor.Enter ( _cache );



if (_cache.Count == 0)
_cache =FilCounty();

Monitor.Exit ( _cache );



return _cache;
}
}
May 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.