singleton application :)

  • Thread starter Thread starter Luca
  • Start date Start date
L

Luca

Hello,

i would like that my windows form application does not start if it has
already been run. Do you have any code example for doing this in c#? I dont
know which method it is best to be used. I would do a check in a routine
called at the application's startup, but i dont know what to check :)

Thanks in advance,
Luca
 
Hi,

Search in the archives, this is discussed from time to time here , you
could use either a Mutex, named pipe, or attach to a particular port ( not
recommended ) or search by a particular process/windows name.

Go to google to search for code.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Pd:
Jon , I think this could be a good thing to include in the FAQ , I may do a
compilation of the differents methods. let me know ..
 
Try creating a mutex in your form load and testing to see if the mutex
already exists...

/// Code starts

bool success;
Mutex mut;

mut = new Mutex(true, "MyUniqueName", out success);

if (success)
{
// Application ok to start
}
else
{
// Application not ok to start
Application.Exit();
}

// Prevent garbage collector getting rid of your mutex object...
GC.KeepAlive(mut);

\\\ Code finishes


Hope this helps

Matt.
 
Hi Ignacio,

It would've been great if .NET had supported named pipes
 
Hi,

There are implementations of it, take a look at
http://examples.oreilly.com/csharpckbk/ they provide it. and I think I that
in gotdotnet or codeproject you can find classes for that. There are a lot
of functionalities that are not present in the framework (even more in the
compact framework ) so you have to rely in third parties code


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Stoitcho Goutsev (100) said:
Hi Ignacio,

It would've been great if .NET had supported named pipes

--

Stoitcho Goutsev (100) [C# MVP]


"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%[email protected]...
Hi,

The answer does exist in the FAQs :
http://www.yoda.arachsys.com/csharp/faq/#one.application.instance

It is in the .NET Core section and not in the Windows Forms section..


Sorry for the confusion.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote
in message news:[email protected]... do
a
 
Hi Ignacio,

Yes, using PInvoke almost all win32 API can be used. That doesn't mean it is
..NET feature. Don't forget that .NET is supposed to be platform independent.

--

Stoitcho Goutsev (100) [C# MVP]


Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

There are implementations of it, take a look at
http://examples.oreilly.com/csharpckbk/ they provide it. and I think I
that
in gotdotnet or codeproject you can find classes for that. There are a lot
of functionalities that are not present in the framework (even more in the
compact framework ) so you have to rely in third parties code


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Stoitcho Goutsev (100) said:
Hi Ignacio,

It would've been great if .NET had supported named pipes

--

Stoitcho Goutsev (100) [C# MVP]


"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%[email protected]...
Hi,

The answer does exist in the FAQs :
http://www.yoda.arachsys.com/csharp/faq/#one.application.instance

It is in the .NET Core section and not in the Windows Forms section..


Sorry for the confusion.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote
in message Hi,

Search in the archives, this is discussed from time to time here , you
could use either a Mutex, named pipe, or attach to a particular port
(
not
recommended ) or search by a particular process/windows name.

Go to google to search for code.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Pd:
Jon , I think this could be a good thing to include in the FAQ , I may do
a
compilation of the differents methods. let me know ..



Hello,

i would like that my windows form application does not start if it has
already been run. Do you have any code example for doing this in c#? I
dont
know which method it is best to be used. I would do a check in a
routine
called at the application's startup, but i dont know what to check
:)

Thanks in advance,
Luca
 
Back
Top