Discussion:
Wrapper for Activator.GetObject
(too old to reply)
c***@gmail.com
2008-08-25 21:31:53 UTC
Permalink
I have some code for a Web service that makes a remoting call.

OnStart of this service, I register the a HTTP channel.
I maintain a global static instance of type Manager at the same time
(singleton).

When my service receives a message/request, calls Manager.Process()
method, and Process calls MyRemoting.Activate(someType, "xxxxx");

Something like:

public class MyRemoting
{
public static object Activate(Type type, string url)
{
return Activator.GetObject(type, url);
}
}

My question is, is this thread-safe? Will multiple requests work fine
when hitting my service at the same time?
Since I don't have any state stored for the MyRemoting class, and the
static instance of Manager is called ever time.

Any help is appreciated.
Thanks.
Michel Posseth [MCP]
2008-10-20 18:55:44 UTC
Permalink
well you could always implement a SyncLock (or lock, as it's called in C#)
just to be sure

http://msdn.microsoft.com/en-us/library/c5kehkcz(VS.71).aspx

Basically, declare an instance -- any instance. A new object() if you want.
Then use that in any calls to SyncLock that you wish to be mutually
exclusive, ie. you wish to only have one of those bits of code run at any
one time.

HTH

Michel Posseth
http://www.vbdotnetcoder.com/.
Post by c***@gmail.com
I have some code for a Web service that makes a remoting call.
OnStart of this service, I register the a HTTP channel.
I maintain a global static instance of type Manager at the same time
(singleton).
When my service receives a message/request, calls Manager.Process()
method, and Process calls MyRemoting.Activate(someType, "xxxxx");
public class MyRemoting
{
public static object Activate(Type type, string url)
{
return Activator.GetObject(type, url);
}
}
My question is, is this thread-safe? Will multiple requests work fine
when hitting my service at the same time?
Since I don't have any state stored for the MyRemoting class, and the
static instance of Manager is called ever time.
Any help is appreciated.
Thanks.
Loading...