Wierd Synchronization Problem in Using .Net Framework Remoting --

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am recently using .net remoting to develop a distributed application and
some synchronization problem bothered for a long time.

The problem looks as following:
There is one server application that hosts a remote object, "mydata". This
remote object is configured as a singlton object. Three functions are
developed within this object to provide synchronized data access:
public class MyData :MarshalByRefObject{

....
public void Lock(){
System.Threading.Monitor.Enter(this);
}

public void Release(){
System.Threading.Monitor.Exit(this);
}

public bool TryLock(){
return System.Threading.Monitor.TryEnter(this);
}
....
}

And two client applications with similar behavior that at first, each client
application tries to obtain the lock on mydata by invoking mydata.Lock();
then does some processing. After the processing is done, the client will
display a message box by invoking 'MessageBox.show()' and waiting for user's
input. After the user's input is received, the client will invoke
mydata.Release() to release the lock on mydata such that other clients may be
able to access mydata.

So I started the first client. The client obtained the lock and displayed
the message box, waiting for my input. Then the second client was started. If
everything were working, the second client should have been blocked since it
can not obtain the lock. Unfortunately, the second client just went on as if
it had got the lock and also displays the message box!

The more wierd thing was that after a random length of time(several minutes
to hours), the lock could work!, i.e. before one client releases the lock,
the other one is blocked at the mydata.Lock() invocation!

So could anybody help me to tell me what's wrong here? Or anybody can tell
me how to implment such a locking in the .net remoting? Thanks a lot!


For one more thing, I am using VS.net 2003 pro and Windows XP running one a
P4 desktop. Thanks!
 
More information I got:
If I do nothing after starts the client, i.e. not trying to access the
remote object, for several minutes, the blocking mechanism works smoothly.
Anyone can give me a hand to let me know what's wrong here? Is that my
program error or a bug of .net framework? Thanks a lot!
 
Back
Top