473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Monitor.Enter

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
4 3474
Hi guys,

Waiting for your soluitons.

Thanks in advance
May 10 '07 #2
Motoma
3,237 Expert 2GB
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
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
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

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

Similar topics

1
by: Jeff Gerber | last post by:
/* This test program will give a "Value cannot be null" error. If the lock in this code is removed (or Monitor.Enter()) the program will run as expected. I have found no explaination in...
5
by: ste | last post by:
this code not work: it is no possible Exit from Monitor Why ? thank ste //////// using System; using System.Collections;
12
by: Brett Robichaud | last post by:
I need to make access to a reference object threadsafe. My natural instinct was to simply use Monitor.Enter() and Exit(). The problem is that the object behind the reference changes frequently,...
1
by: Jeff Gerber | last post by:
/* This test program will give a "Value cannot be null" error. If the lock in this code is removed (or Monitor.Enter()) the program will run as expected. I have found no explaination in...
5
by: Ken Varn | last post by:
If I have a value type such as int that I want to protect in a multi-threaded situation, Is it safe to use Monitor::Enter(__box(value))? I am thinking that a different object pointer is generated...
8
by: Michael Kennedy | last post by:
Hi, I have been looking into the claim that the keyword lock is not safe when exceptions are possible. That lead me to try the following code, which I think has uncovered a serious error in the...
6
by: Clark Sann | last post by:
Can someone help me understand what object should be used as the lock object? I've seen some programs that use Monitor.Enter(Me). Then, in those same programs, they sometimes use another object. ...
2
by: www.brook | last post by:
I have a VC++.net code. Two threads are created, one thread keeps appending elements to the queue, another keeps deleting an element from the queue. I tried to use monitor, but it seems that the...
2
by: Ian | last post by:
Monitor::Enter and Monitor::Exit must be called in pairs. Is there a way to determine if Monitor::Exit has been called so that it does not get called a second time? The psuedocode below...
13
by: AliRezaGoogle | last post by:
Dear Members, I have a problem in the concepts of Monit.Enter and Monitor.Exit (Before everything I should say that I know how to solve this problem by using Monitor.Wait and I do not need a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.