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

Single Instance

How to prevent my app from being instanced more than once
Nov 15 '05 #1
4 1274
You can use a Mutex for this.

example:

using System;
using System.Windows.Forms;
using System.Threading;

class WinApp : Form
{
static void Main()
{
bool firstInstance;
Mutex m = new Mutex(true, "unique_name_here", out firstInstance);

if(firstInstance)
{
Application.Run(new WinApp());
}
else
{
MessageBox.Show("already running!");
}

}
}
Regards, Mikael

"Shawn" <hu*****@stpass.com> skrev i meddelandet
news:uM**************@TK2MSFTNGP09.phx.gbl...
How to prevent my app from being instanced more than once

Nov 15 '05 #2
Hi,
Check this out:
http://www.planet-source-code.com/vb...=111&lngWId=10

Regards
Benny

Shawn wrote:
How to prevent my app from being instanced more than once


Nov 15 '05 #3
Create a named ManualResetEvent and try to obtain it with a timeout of
zero. If it is not set then set it. The next instance will try to do the
same but will see that the event is signaled. It should then exit
immediatelly.

Shawn wrote:
How to prevent my app from being instanced more than once

--
Dennis Doomen
Sioux T.S.O. Netherlands

de***********@sioux.nl

Nov 15 '05 #4
Here's a link to a user sample. I haven't looked at it to see if it's any
good...

http://www.gotdotnet.com/Community/U...9-4a71432e1f14

--
Mike Mayer
http://www.mag37.com/csharp/
mi**@mag37.com
"Shawn" <hu*****@stpass.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
How to prevent my app from being instanced more than once

Nov 15 '05 #5

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

Similar topics

16
by: Elad | last post by:
Hi, I have an application that is made up of several executables. I need all these executables to use the same instance of an object. What is the best, most efficient way to approach this? ...
18
by: Steve Barnett | last post by:
I want to ensure that there is only ever one instance of my app running on a single PC at any time. I understand that I can achieve this by using a mutex and, if I can't take ownership of the...
7
by: jsale | last post by:
I have made an ASP.NET web application that connects to SQL Server, reading and writing data using classes. I was recommended to use session objects to store the data per user, because each user...
1
by: Maileen | last post by:
Hi, How can i do (and test) a single instance of my form ? thanks, Maileen
9
by: MrSpock | last post by:
1. Create a new Windows Application project. 2. Open the project properties and check "Make single instance application". 3. Build. 4. Go to the release folder and run the application. 5. Try to...
3
by: sadanjan | last post by:
Hi , Appreciate if someone can clarify if database Share Memory Limit (2 GB ) in Unix 32 bit boxes is the top limit for all the databases put together in a database or is it for each of the...
3
by: Mark Jerde | last post by:
VS 2005. When I google "CSharp single instance form" the returned pages usually use a Mutex or the VB.NET runtime library....
13
by: JohnQ | last post by:
Why would anyone write: class SomeThing // class littered with non-domain single-instancing code :( { private: SomeThing(); static SomeThing* pInstance_; public: static SomeThing*...
3
by: sklett | last post by:
I suspect the answer might be in one of the words of my subject, but here goes anyway. I'm working on a system that will execute a very long (300+) chain of task objects. Here is some quick...
5
by: Sarath | last post by:
I've to write a single instance class. there are different methods to control the single instance of a program. I've tried the following method class CSingleton { public: CSingleton&...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.