473,765 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

second instance

how do i prevent the second instance of my app from being instanced when one
is already running?
Nov 15 '05 #1
3 1448
Hi

Singleton assures that there is one and only one instance
of the class and provides a global point of access to
it.There are number of cases in programming where you
need to make sure that there can be one and only one
instance of a class e.g Window Manager,Print Spooler etc.

you can use a private constructor to prevent programmers
from creating instances of Singleton

Check out the following article:
http://www.dotnetextreme.com/code/SingletonCs.asp

Ravikanth[MVP]

-----Original Message-----
how do i prevent the second instance of my app from being instanced when oneis already running?
.

Nov 15 '05 #2
Ravikanth,

I think Shawn is trying to prevent a second instance of his "Program"
running. To do this it is common to obtain a exclusive lock on a file or
other shared resource when a program starts, and check to see if it is
possible (i.e. no other instance of the app has already obtained the lock).

Hope this helps,
Kieran

"Ravikanth[MVP]" <dv*********@ho tmail.com> wrote in message
news:0b******** *************** *****@phx.gbl.. .
Hi

Singleton assures that there is one and only one instance
of the class and provides a global point of access to
it.There are number of cases in programming where you
need to make sure that there can be one and only one
instance of a class e.g Window Manager,Print Spooler etc.

you can use a private constructor to prevent programmers
from creating instances of Singleton

Check out the following article:
http://www.dotnetextreme.com/code/SingletonCs.asp

Ravikanth[MVP]

-----Original Message-----
how do i prevent the second instance of my app from

being instanced when one
is already running?
.

Nov 15 '05 #3
Ravikanth[MVP] <dv*********@ho tmail.com> wrote:
Singleton assures that there is one and only one instance
of the class and provides a global point of access to
it.There are number of cases in programming where you
need to make sure that there can be one and only one
instance of a class e.g Window Manager,Print Spooler etc.

you can use a private constructor to prevent programmers
from creating instances of Singleton

Check out the following article:
http://www.dotnetextreme.com/code/SingletonCs.asp


Kieran has pointed out why this isn't actually useful in this case, but
I'd also like the say that the article you reference doesn't give a
thread-safe implementation of Singleton. There are much better ways of
implementing it.

See http://www.pobox.com/~skeet/csharp/singleton.html

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4061
by: olegkon | last post by:
Hi, I am trying to create 2 separate environments (dev and test) on one powerful Unix server which has 2 network cards, 2 IP addresses, 2 server names... Using Apache 2.0.43 and Tomcat 4.1.29/JBoss 3.0.7, mod_jk 2.0.43 on Solaris 9, Intranet environment, Cocoon apps.
5
2363
by: Tobiah | last post by:
What is the purpose of the second argument to super()? What is meant by the returning of an 'unbound' object when the argument is omitted. Also, when would I pass an object as the second argument, and when would I pass a type? Thanks,
2
2020
by: johnmann56 | last post by:
Hello. I have written a simple image viewer application using C# .NET. It only needs to display one image at a time. When a different program, in C, running on the same machine, does a "system(myfile.a2d2)" call, it automatically starts my image viewer application (using file type association). a2d2 is the image file format, my own. If the C program does the system call again for a different image, I find that it starts a new instance of...
1
1521
by: Jon Pope | last post by:
I've got an application that uses a Mutex to prevent multiple instances of the application from launching. This works great for me. However, what I would like to do is when a second attempt to launch the application is detected, it activates the first instance then closes the second instance. At app startup, how can I grab a reference to another instance of my app so that I can signal to it to activate itself? Cheers, Jon
3
2186
by: DotNetNewbie | last post by:
I am reading the book Teach Yourself Microsoft Visual Basic .Net 2003 in 21 Days. I am having trouble getting one of the exercises to work at the end of day 4. Exercises: 1. Create a new multiple-form application that displays two forms when it starts, each with a text box. Add code to each text box’s TextChanged event (this is the
0
1963
by: Wayne | last post by:
Original Post: The following problem started on my PC about a week ago and I can't link it to any specific change. I'm using Access XP. If I have any database open and try to open any other database by double clicking its file in Explorer, it takes about 5 seconds to open. Previously the second database would open almost instantaneously, as one would expect on a reasonably fast machine.
5
3908
by: Mike | last post by:
I'm having trouble accessing SQL2005 Standard Edition as a second instance of SQL Server where the first instance is SQL 2000 Enterprise Edition. I installed SQL 2005 as a named instance "SQL2005". The server is running Windows 2000 SP4 ON A 32-Bit machine. When I look in Services I see the SQL Server (SQL2005), SQL Server Agent (SQL2005) services there. I went into SQL Server Configuration manager and disabled the named pipes protocol...
0
1724
by: Massimiliano Campagnoli | last post by:
Can you explain me what is going on here ? J:\ is a network drive located on a samba server. DB2 is V7.2 fixpak 14. net use j: \\linuxserver\backupdb2 The command completed successfully. DB2 BACKUP DATABASE SAMPLE USER MAXI USING 110ELODE TO J:\
0
1917
by: david12842 | last post by:
I already have a mysqld running on port 3306 on my linux system and want a second instance on a different port. This is a totally different instance, I don't want it to share data tables or anything else with the first instance. I tried running mysqld --defaults-file=config.conf where config.conf is my other config file with the new port and datadir, tried using absolute paths, everything, and kept getting this error: Could not open required...
0
10153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9946
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6646
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3530
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.