Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Alternatives
 

Run Only One Copy Of Application

, 25 Mar 2011
Maybe this is helpful, it tries to switch to the first running instance:namespace UltraSimple.Win{ static class Program { [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr hWnd); [STAThread] ...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

12 Apr 2011
KevinPorter
How about using a Mutex? This should also work for Terminal Services sessions. Use in Program.csstatic Mutex mut;try{ bool isOwned = false; mut = new Mutex(true, Application.ProductName + " MUTEX: {53A4988C-F91F-4054-9076-220AC5EC03F3}", out isOwned); if (!isOwned)...
6 Nov 2011
RaviRanjankr
Yet another way to this is as follows: using System;using System.Collections.Generic;using System.Windows.Forms;using System.Threading;namespace OnlyOneInstance{ static class Program { [STAThread] static void Main() { bool...
19 Mar 2011
charles henington
5 alternatives  
Run Only One Copy Of Application
30 Mar 2011
tlhintoq
Just because we like C# doesn't mean we can't borrow from other .NET languages. I've always had good luck and less complication using VB's single instance methodology in my C# applications. This code would go in your program.cs file:/// /// We inherit from...
29 Mar 2011
Neil A. Harding
I actually use code like this, which allows me to detect a existing instance and to call the original instance with the command line (I expand any filenames present so that it can access the filenames even if the original path is different).string processName =...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

FDW

Netherlands Netherlands
No Biography provided

| | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 25 Mar 2011
Article Copyright 2011 by FDW
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid