|
-
January 27th, 2005, 03:40 PM
#1
.Net Remoting Concurrency issue
Using .Net remoting I create singleton serverside object that has some methods.
When Clients call the methods, how can I enforce concurrency in the sense that each
Method is called at a time and if other client call the same method, have it be put in the queue.
It there any way to do it through static methods or thread safe way???
Thank you
-
January 27th, 2005, 06:14 PM
#2
Re: .Net Remoting Concurrency issue
Add synchronization to the methods same as you would for implementing any thread safe class.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
January 27th, 2005, 06:22 PM
#3
Re: .Net Remoting Concurrency issue
could you elaborate on how to do it please
-
January 27th, 2005, 07:41 PM
#4
Re: .Net Remoting Concurrency issue
Look up the 'lock' keyword :
Code:
class MyExample
{
private int m_nValue = 0;
public int Integer
{
get
{
lock (this)
{
return m_nValue;
}
}
set
{
lock (this)
{
m_nValue = value;
}
}
}
}
Should be self explanitory.
There are other ways of doing synchronisation (i.e. making sure a piece of code is only entered once at a time) but this is probably the easiest in C#.
Darwen.
-
February 3rd, 2005, 11:05 AM
#5
Re: .Net Remoting Concurrency issue
thank you for the code.
by 'this' do you refer to the method??
As far as I know lock lokst the varibales but not the methods itself, am I right??
-
February 3rd, 2005, 11:39 AM
#6
Re: .Net Remoting Concurrency issue
Lock refers to the class instance.
This of it this way :
Whatever you pass into the lock is used as a variable to perform the lock.
Another lock on this variable will cause it to block until the lock on the variable is released.
So you can do this :
Code:
class MyClass
{
private string m_sString = null;
public MyClass()
{
m_sString = "Hello";
}
void GetString1()
{
lock (this)
{
return m_sString;
}
}
void GetString2()
{
lock (m_sString)
{
return m_sString;
}
}
}
GetString1() allows GetString2() to be called by a seperate thread.
Seperate threads will block on multiple calls to GetString1().
Get the idea ? Locking a class doesn't lock all members.
Don't forget to rate....
Darwen.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|