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

Singleton and concurrency in .NET 2.0

P: n/a
Hello,

I have some questions about Singleton and concurrency, I'd appreciate
any help you can give me.

I have a Windows Service which, on start, registers on remoting (using
IPC channel and WellKnownObjectMode.Singleton) a 'Test' class.

public class Test
{
public void SendMessage()
{
// etc. etc.
}
}

1. First, just to be sure, the instantiation and singleton
implementation is already provided by Remoting, right? Because I just
ask for the object using Activator.GetObject and I receive it without
additional code.

2. If two (or more) simultaneous invocations to SendMessage() occurs,
is the execution sequential? I mean, the first thread executes
SendMessage() and the second waits for the first to finish? Or both of
them executes the method at the same time?

3. In case the execution is sequential, if I'd want to SendMessage() be
executed simultaneously any times as invoked, it would be correct that
SendMessage() be just a wrapper that creates a new Thread and executes
inside it a method i.e. SendMessageImpl()?

Thank you in advance.

Luis

Apr 4 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Luis,

See inline:
1. First, just to be sure, the instantiation and singleton
implementation is already provided by Remoting, right? Because I just
ask for the object using Activator.GetObject and I receive it without
additional code.
Yes, the remoting infrastructure will handle the instantiation.

2. If two (or more) simultaneous invocations to SendMessage() occurs,
is the execution sequential? I mean, the first thread executes
SendMessage() and the second waits for the first to finish? Or both of
them executes the method at the same time?
No, the execution is not sequential, you will have to write thread-safe
code.
3. In case the execution is sequential, if I'd want to SendMessage() be
executed simultaneously any times as invoked, it would be correct that
SendMessage() be just a wrapper that creates a new Thread and executes
inside it a method i.e. SendMessageImpl()?
No need to do this, since the calls are not sequential.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

Thank you in advance.

Luis

Apr 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.