Re: Ensure only one instance running
Mark Brackett <[email protected]> Fri, 21 Dec 2007 09:01:46 -0500
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <[email protected]> |
VB.NET has Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase exposed by the Properties page that allows a single checkbox to control single instance. You can use it from C# by adding a reference to Microsoft.VisualBasic.dll and inheriting from it...but it might make you feel dirty. ;) --MB > -----Original Message----- > From: Discussion forum for developers using Windows Forms to build apps > and controls [mailto:[email protected]] On Behalf Of > Graeme Hood > Sent: Friday, December 21, 2007 8:53 AM > To: [email protected] > Subject: [DOTNET-WINFORMS] Ensure only one instance running > > I have this code to make sure my app can't run twice. But I seem to > remember there was a newer/better way in the latest .Net FW. > > Is there? > > ==================================================== > > public static void Main() > > bool firstInstance = false; > > string safeName = Application.UserAppDataPath.Replace(@"\", "_"); > > Mutex mutex = new Mutex(true, safeName, out firstInstance); > > if (!firstInstance) return; > > This email message is intended only for the use of the named recipient. > Information contained in this email message and its attachments may be > privileged, confidential and protected from disclosure. If you are not > the > intended recipient, please do not read, copy, use or disclose this > communication to others. Also please notify the sender by replying to > this > message and then delete it from your system.