473,386 Members | 1,801 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,386 software developers and data experts.

Singleton and concurrency in .NET 2.0

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
1 1907
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Stephen Brown | last post by:
I have some strange behavior on my web server that seems to point to garbage collection. I have a singleton that tracks web activity on my web site. The singleton works great, except that it...
5
by: Ajay Pal Singh | last post by:
Hi, I've one question related to singelton implementation of a class. Suppose a class is as Singelton and contains a public method. If there are more than one requests for the same method...
9
by: oleggus | last post by:
I hope, I misunderstood some basics here and it is easy to solve.. I need a singleton object running on server which can be used(write and read) by different client interfaces - for example there...
0
by: Jeff Louie | last post by:
Johns ? got me to thinking so here is some prototype code that attempts to subclass a singleton. namespace SubclassSingleton { class NoahsArkWithOneMale { private Animal afa = new Animal;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.