[ djmrky @ 12.09.2005. 09:47 ] @
kako onemoguciti da se startuje aplikacija vise puta Pozdrav |
[ djmrky @ 12.09.2005. 09:47 ] @
[ Java Beograd @ 12.09.2005. 09:59 ] @
Code: using System; using SpecialServices; namespace MyNameSpace { public class MyForm : System.Windows.Forms.Form { private System.ComponentModel.Container components = null; public MyForm() { InitializeComponent(); ... } [STAThread] static void Main() { using(SingleProgramInstance spi = new SingleProgramInstance("MyForm")) { if (spi.IsSingleInstance) { try { Application.Run(new MyForm()); } catch (Exception e) { ... } Application.ExitThread(); } else { MessageBox.Show("Bla, bla", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } ... } Poenta je, očigledno u main funkciji. Sad ću da okačim i dll [ djmrky @ 12.09.2005. 11:16 ] @
e pa hvala, to je to
btw, a jel ovaj dll freeware posto mi je neophodan takav Pozdrav [ Java Beograd @ 12.09.2005. 11:32 ] @
Source code je preuzet sa www.codeproject.com a dll sam izbildovao lično i personalno. E sad, da li se sme koristiti, proceni sam.
[ nervozica @ 12.09.2005. 12:58 ] @
Code: [DllImport("kernel32.dll", EntryPoint="CreateMutexA")] private static extern int CreateMutex ( IntPtr lpMutexAttributes, int bInitialOwner, string lpName); [DllImport("kernel32.dll")] private static extern int GetLastError (); private const int ERROR_ALREADY_EXISTS = 183; public static bool IsInstanceRunning() { bool bIsRunning = false; try { string appname = Assembly.GetExecutingAssembly().GetName().Name; if ((CreateMutex(IntPtr.Zero, 1, appname ) != 0) && (GetLastError() == ERROR_ALREADY_EXISTS)) bIsRunning = true; } catch (Exception ex) { MessageBox.Show("Instance Error: " + ex.ToString()); } return bIsRunning; } static void Main() { if(IsInstanceRunning()) Application.Exit(); else Application.Run(new Form1()); } [ ZokiR @ 13.09.2005. 01:36 ] @
A može i bez interopa:
Code: using System.Threading; using System.Diagnostics; ... static void Main() { bool createdNew; Mutex singleInstanceMutex = new Mutex(true, Process.GetCurrentProcess().ProcessName, out createdNew); try { if (createdNew) { Application.Run(new Form1()); } } finally { singleInstanceMutex.Close(); } } Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|