Exemplo n.º 1
0
        static void Main()
        {
            System.Threading.Mutex mutex = new System.Threading.Mutex(false, "{8D719F92_EA4B_41F1_9905_0C914E45414C_Ololap");
            try
            {
                if (mutex.WaitOne(0, false))
                {
                    // Run the application
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm());
                }
                else
                {
                    MessageBox.Show("Another instance of the application is already running.\nPlease close all the other instances if you want to open the new one",
                        "Application cannot be run", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            finally
            {
                if (mutex != null)
                {
                    mutex.Close();
                    mutex = null;
                }
            }

        }
Exemplo n.º 2
0
 public Pos(int Port, int PosID, int BaudRate = 9600)
 {
     this.Port = Port;
     this.POS_id = PosID;
     this.BaudRate = BaudRate;
     this.mutex = new System.Threading.Mutex();
 }
Exemplo n.º 3
0
        static void Main(string[] arg)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                mutex = new System.Threading.Mutex(false, @"{747690E4-BCE9-4949-9B79-FBAC7E700D63}");
                if (!mutex.WaitOne(0, false))
                {
                    Process prevProcess = GetPreviousProcess();
                    if (prevProcess != null && prevProcess.MainWindowHandle != IntPtr.Zero)
                    {
                        // 起動中のアプリケーションを最前面に表示
                        WakeupWindow(prevProcess.MainWindowHandle);
                    }
                    return;
                }

                switch (arg.Length)
                {
                    case 0:
                        Application.Run(new Form1());
                        break;
                    case 3:
                        loginState form = new loginState(arg[0], arg[1], bool.Parse(arg[2]));
                        Application.Run(form);
                        break;
                }
            }
            finally
            {
                mutex.Close();
            }
        }
Exemplo n.º 4
0
        private static void Main()
        {
            if( Properties.Settings.Default.newFileFlag ) {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.newFileFlag = true;
                Properties.Settings.Default.Save();
            }

            // 多重起動対策
            using( var mutex = new System.Threading.Mutex( false, Application.ProductName ) ) {
                if( mutex.WaitOne( 0, false ) ) {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault( false );
                    var mainForm = new MainForm();
                    if( (Options.StartupState)Properties.Settings.Default.startupState == Options.StartupState.NORMAL ) {
                        Application.Run( mainForm );
                    } else {
                        Application.Run();
                    }
                } else {
                    var hThisProcess = Process.GetCurrentProcess();
                    var hProcesses = Process.GetProcessesByName( hThisProcess.ProcessName );
                    var iThisProcessId = hThisProcess.Id;

                    foreach( var hProcess in hProcesses.Where( hProcess => hProcess.Id != iThisProcessId ) ) {
                        Win32.Window.ShowWindow( hProcess.MainWindowHandle, Win32.Window.SW_NORMAL );
                        Win32.Window.SetForegroundWindow( hProcess.MainWindowHandle );
                        break;
                    }
                    MessageBox.Show( "既にLordOfRangerが起動されています。" );
                }
            }
        }
Exemplo n.º 5
0
        System.Threading.Mutex _Mutex; //Used to determine if the application is already open

        #endregion Fields

        #region Methods

        public bool CheckPrevious(int wParam)
        {
            //Check for previous instance of this app
            lock (mutexLock)
            {
                m_uniqueIdentifier = Application.ProductName;
                _Mutex = new System.Threading.Mutex(false, m_uniqueIdentifier);
            }
            // First register the windows message
            MessageId = NativeMethods.RegisterWindowMessage(m_uniqueIdentifier);
            if (_Mutex.WaitOne(1, true))
            {
                //we are the first instance don't need to do anything
                return true;
            }
            else
            {
                // Cause the current form to show
                // Now broadcast a message to cause the first instance to show up
                Int32 BSMRecipients = BSM_APPLICATIONS; //Only go to applications
                Int32 tmpuint32 = 0;
                tmpuint32 = tmpuint32 | BSF_IGNORECURRENTTASK; //Ignore current app
                tmpuint32 = tmpuint32 | BSF_POSTMESSAGE; //Post the windows message
                int ret = NativeMethods.BroadcastSystemMessage(tmpuint32, ref BSMRecipients, MessageId, wParam, 0);
                //A different instance already exists exit now.
                return false;
            }
        }
Exemplo n.º 6
0
        /* mutex tries to create a mutex lock, titled "MathDrills". result will be whether or not that succeeded. It won't succeed if it is already locked
         * GC.KeepAlive means that the garbage collector will never release that mutex.
         * 
         * If it could not get the mutex lock, then don't bother running the rest of the program.
         */
        static void Main()
        {
            bool result;
            rng = new Random();
            var mutex = new System.Threading.Mutex(true, "MathDrills", out result);
            if (!result)
            {
                MessageBox.Show("The game is already open in another window.");
                return;

            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Directory.CreateDirectory(@"c:\users\public\MathDrills\ProblemSets"); //Make sure there is a directory into which to save the problems
            
            initializeConfigFile();
            //initializeUserList();
            //Aurelio Arango
            //3-31-14 

            xml = new XML_Handler();
            xml.create_xml(xml.check_xml_exists(USERSFILE));
            loadData();
            Application.Run(new StartForm());

            //Application.Run(new LoginForm());
            GC.KeepAlive(mutex);
        }
Exemplo n.º 7
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            bool result;
            var mutex = new System.Threading.Mutex(true, "IMgmt", out result);
            try
            {

                if (!result)
                {
                    MessageBox.Show("Another instance is already running.");
                    return;
                }
                if (!EventLog.SourceExists(sSource))
                    EventLog.CreateEventSource(sSource, sLog);
                Application.Run(new frmSplash());
                GC.KeepAlive(mutex);
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("Inventory Mgmt", ex.Message + ":" + ex.InnerException + ":" + ex.StackTrace.ToString());
            }
            finally
            {
                mutex.ReleaseMutex();
            }
        }
Exemplo n.º 8
0
        static void Main()
        {
            //string[] args = Environment.GetCommandLineArgs();
            //if (args.Length > 1)
            //{
            //    string url = args[1];
            //    url=url.Replace("{", "").Replace("}","");
            //    try
            //    {
            //        CodeAnalyser.Download(url);
            //    }
            //    catch (Exception ex)
            //    {
            //        MessageBox.Show(ex.Message);
            //    }
            //}

            bool createdNew;
            System.Threading.Mutex m = new System.Threading.Mutex(true, "Your App here", out createdNew);

            if (!createdNew)
            {
                return;
            }

            {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new ToolForm());

            } GC.KeepAlive(m); // important!
        }
Exemplo n.º 9
0
        static void Main()
        {
            Guid assemblyGuid = Guid.Empty;
              object[] assemblyObjects = System.Reflection.Assembly.GetEntryAssembly().GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), true);
              if (assemblyObjects.Length > 0)
              {
            assemblyGuid = new Guid(((System.Runtime.InteropServices.GuidAttribute)assemblyObjects[0]).Value);
              }

              bool granted;
              System.Threading.Mutex m = new System.Threading.Mutex(true, assemblyGuid.ToString(), out granted);

              if (granted)
              {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
              }
              else
              {
            MessageBox.Show("Application is already running");
              }

              m.Close();
        }
Exemplo n.º 10
0
        static void Main()
        {
                        //Create mutex at application start and try to get the ownership
            using (var m = new System.Threading.Mutex(true, "HandGestureRecognition", out isNew))
            {
                //If application owns the mutex, continue the execution
                if (isNew)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
                }
                //else show user message that application is running and set focus to that application window
                else
                {
                    MessageBox.Show("Application already running", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Process current = Process.GetCurrentProcess();

                    foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                    {
                        
                        if (process.Id != current.Id)
                        {

                            SystemParametersInfo((uint)0x2001, 0, 0, 0x0002 | 0x0001);
                            ShowWindowAsync(process.MainWindowHandle, WS_SHOWNORMAL);
                            SetForegroundWindow(process.MainWindowHandle);
                            SystemParametersInfo((uint)0x2001, 200000, 200000, 0x0002 | 0x0001);
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        static void Main()
        {
            bool SingleApp = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["SingleApp"]);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (!SingleApp)
            {
                Application.Run(new Form1());
            }
            else
            {
                bool bExist = false;
                System.Threading.Mutex mm = new System.Threading.Mutex(true, "IntServer", out bExist);
                if (bExist)
                {
                    Application.Run(new Form1());
                    mm.ReleaseMutex();
                }
                else
                {
                    //查找窗体
                    IntPtr handle = WindowAPI.FindWindow(null, "WIFI-COM网络数据调试工具");
                    if (handle != IntPtr.Zero)
                    {
                        //恢复窗口并设置为前台窗口
                        WindowAPI.SetForegroundWindow(handle);
                        WindowAPI.OpenIcon(handle);
                        //PostMessage(handle, WM_SYSCOMMAND, (IntPtr)SC_DEFAULT, IntPtr.Zero);
                    }
                }
            }
        }
Exemplo n.º 12
0
        static void Main()
        {
            // Determine if an instance is already running?
            bool firstInstance;
            string mName = string.Format("Local\\RdlDesigner{0}", version);
            //   can't use Assembly in this context
            System.Threading.Mutex mutex = new System.Threading.Mutex(false, mName, out firstInstance);

            if(firstInstance)
            {// just start up the designer when we're first in line
                var thread = System.Threading.Thread.CurrentThread;

                thread.CurrentCulture = new CultureInfo(thread.CurrentCulture.Name);

                if(thread.CurrentCulture.Equals(CultureInfo.InvariantCulture))
                {
                    thread.CurrentCulture = new CultureInfo("en-US");
                }
                // for working in non-default cultures
                thread.CurrentCulture.NumberFormat.NumberDecimalSeparator = ".";
                thread.CurrentUICulture = thread.CurrentCulture;

                Application.EnableVisualStyles();
                Application.DoEvents();
                Application.Run(new RdlDesigner(ipcChannelPortName, false));
                return;
            }

            // Process already running.   Notify other process that is might need to open another file
            string[] args = Environment.GetCommandLineArgs();
        }
Exemplo n.º 13
0
        private static bool EnsureSingleLoad()
        {
            bool result;
            var mutex = new System.Threading.Mutex(true, "Postworthy.Tasks.Bot." + UsersCollection.PrimaryUser().TwitterScreenName, out result);

            return result;
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            bool ok;
            System.Threading.Mutex m = new System.Threading.Mutex(true, "__MSDN_HV2VIEWER_LADSOFT__", out ok);

            if (! ok)
            {
                if (args.Length == 1)
                    PipeClient.Write(args[0]);
            }
            else
            {
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.AssemblyResolve += new ResolveEventHandler(ResolveAssembly);

                Application.ApplicationExit += OnApplicationExit;

                PipeServer.Start(PipeServerCallback);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                mainWindow = new Form1(args);
                Application.Run(mainWindow);
                GC.KeepAlive(m);                // important!
            }
        }
Exemplo n.º 15
0
        private static bool EnsureSingleLoad()
        {
            bool result;
            var mutex = new System.Threading.Mutex(true, "Postworthy.Tasks.StreamMonitor", out result);

            return result;
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            #region 处理来自参数的快速启动请求,跳过对OPCSERVER的三分钟等待
            foreach (string arg in args)
            {
                if (arg.Contains("fast"))
                {
                    waitMillionSecond = 1000;
                    break;
                }

            }
            #endregion
            bool createNew;
            //try
            //{
            //Console.WriteLine(Application.ProductName);
            using (System.Threading.Mutex m = new System.Threading.Mutex(true, "Global\\" + Application.ProductName, out createNew))
            {
                if (createNew)
                {
                    IniFile ini = new IniFile(AppDomain.CurrentDomain.BaseDirectory + "MicroDAQ.ini");

                    DatabaseManager = new DatabaseManager(ini.GetValue("Database", "Address"),
                                                        ini.GetValue("Database", "Port"),
                                                        ini.GetValue("Database", "Database"),
                                                        ini.GetValue("Database", "Username"),
                                                        ini.GetValue("Database", "Password"));
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    Form MainForm = null;
                    while (!BeQuit)
                        try
                        {
                            MainForm = new MainForm();
                            //frmMain = new TestAlarm();
                            Application.Run(MainForm);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("OH. NO!" + ex.ToString());
                        }
                        finally
                        {
                            if (MainForm != null) MainForm.Dispose();
                        }
                    Environment.Exit(Environment.ExitCode);
                }
                else
                {
                    MessageBox.Show("程序已经在运行,无法再次启动。", "已启动", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
            //}
            //catch
            //{
            //    MessageBox.Show("Only one instance of this application is allowed!");
            //}
        }
Exemplo n.º 17
0
        static void Main()
        {
            bool mutexCreated = false;
            System.Threading.Mutex mutex = new System.Threading.Mutex( true, @"Local\TimeTrack.exe", out mutexCreated );

            // only want once instance open at a time.
            // if the application is already open, then scan the processes to find out which
            // one it is, and give it focus.
            if(mutexCreated) {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new timerMainForm());
            } else {
                // scan the processes, find the one that is ours, and focus to it
                Process current = Process.GetCurrentProcess();
                foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                {
                    if (process.Id != current.Id)
                    {
                        SetForegroundWindow(process.MainWindowHandle);
                        break;
                    }
                }
            }

            mutex.Close();
        }
Exemplo n.º 18
0
        private static bool EnsureSingleLoad()
        {
            bool result;
            var mutex = new System.Threading.Mutex(true, "Postworthy.Tasks.LanguageAnalytics", out result);

            return result;
        }
Exemplo n.º 19
0
 static void Main()
 {
     bool createNew;
     using (System.Threading.Mutex m = new System.Threading.Mutex(true, Application.ProductName, out createNew))
     {
         if (createNew)
         {
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             var printClient = new PrintClient();
             if (!printClient.IsServerOK)
             {
                 return;
             }
             //Application.Run(new Login());
             Application.Run(printClient);
         }
         else
         {
             MessageBox.Show("Only one instance of this application is allowed!");
         }
     } 
     //Application.EnableVisualStyles();
     //Application.SetCompatibleTextRenderingDefault(false);
     //Application.Run(new PrintClient());
     //Application.Run(new Login());
 }
Exemplo n.º 20
0
        static void Main()
        {
            bool runone;
            System.Threading.Mutex run = new System.Threading.Mutex(true, "hnbthelper", out runone);
            //验证是否启动当前系统两次
            if (!runone)
            {
                MessageBox.Show("【湖南补贴系统助手】程序已经运行,请查看右下角的系统托盘区域!", "提示");
                return;
            }
            // 验证应用程序是否被改名,启动程序改名后将不允许运行
            string exeName = Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf("\\") + 1);
            if (!exeName.ToLower().Equals("hnbthelper.exe"))
            {
                MessageBox.Show("无法找到启动程序!", "提示");
                return;
            }
            //string oraclePath = System.Windows.Forms.Application.StartupPath;
            //Environment.SetEnvironmentVariable("PATH", oraclePath, EnvironmentVariableTarget.Process);
            //Environment.SetEnvironmentVariable("NLS_LANG", "SIMPLIFIED CHINESE_CHINA.ZHS16GBK", EnvironmentVariableTarget.Process);
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            frmLogin login = new frmLogin();
            login.ShowDialog();
            if (login.DialogResult == DialogResult.OK)
            {

                Application.Run(new frmMain());
            }
            else { return; }
        }
Exemplo n.º 21
0
        static void Main()
        {
            bool tryCreateNewApp;
            mInstance = new System.Threading.Mutex(true, mAppName, out tryCreateNewApp);
            if (!tryCreateNewApp)
            {
                MessageBox.Show("The program has been already started.");
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            try
            {
                Application.Run(new EditorForm());
            }
            catch (Exception ex)
            {
                //Log.LogMessage(ex);
                //string message = "Send log file to developers for fixing problem.\r\nThe program will be closed.";
                //Log.LogMessage(message);
                //mInstance.ReleaseMutex();
                mInstance.Close();
                mInstance.Dispose();
                new ErrorRestart(KeyProgram.eDoctrinaOcrEd).ReStart(ex);
            }
        }
Exemplo n.º 22
0
 static void Main( )
 {
     bool ret;
     System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out ret);
     if (ret)
     {
         Application.EnableVisualStyles( );
         Application.SetCompatibleTextRenderingDefault(false);
         //Application.Run(new FingerTest( ));
         //Application.Run(MainMetroForm.Instance);
         Utilities.CreateDesktopShortCut( );
         AppContext.IsRuning = true;
         ServiceProvider.Init( );
         if (new LoginForm( ).ShowDialog( ) == DialogResult.OK)
             Application.Run(MainMetroForm.Instance);
         else
             Application.Exit( );
     }
     else
     {
         MessageBox.Show("已经有相同的应用程序在运行,请不要同时运行多个本程序。\n\n这个程序即将退出。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         //   提示信息,可以删除。
         Application.Exit( );//退出程序
     }
 }
Exemplo n.º 23
0
        public static void Main()
        {
            bool activo;
            System.Threading.Mutex m = new System.Threading.Mutex(true, "LimpiezasPalmeralForms", out activo);

            if (!activo)
            {
                MessageBox.Show("Ya se ha iniciado la aplicación");
                Application.Exit();
            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                try
                {
                    //Application.Run(new Login());
                    Application.Run(new PantallaPrincipal());
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.Message.ToString() + '\n' + ex.StackTrace);
                }
            }
            // Se libera la exclusión mutua
            m.ReleaseMutex();
        }
Exemplo n.º 24
0
		public bool GetMutex()
		{
			bool acquired;
			_appMutex = new System.Threading.Mutex(true, "KeyMapperAppMutex", out acquired);
			
			return acquired;
		}
Exemplo n.º 25
0
        static void Main()
        {
            System.Threading.Mutex Mu = new System.Threading.Mutex(false, "{ed4a1d54-416d-47eb-adb6-9a2d47e96774}");
            if (Mu.WaitOne(0, false))
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Settings settings = new Settings();

                Writer log = new Writer(settings);

                ForegroundWindow foregroundWindow = new ForegroundWindow();

                #region NotifyIconMenu
                ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
                NotifyIconMenu notifyIconMenu = new NotifyIconMenu(contextMenuStrip, settings);
                notifyIconMenu.FocusHandler = foregroundWindow;
                notifyIconMenu.AddMenuItem(new TextEimer.Windows.MenuItems.Separator());
                notifyIconMenu.AddMenuItem(new TextEimer.Windows.MenuItems.Options("Optionen", settings));
                notifyIconMenu.AddMenuItem(new TextEimer.Windows.MenuItems.QuitItem("Beenden", "quit"));
                notifyIconMenu.LogWriter = log;
                #endregion

                #region NotifyIcon
                NotifyIcon notifyIcon = new NotifyIcon();
                notifyIcon.ContextMenuStrip = notifyIconMenu.contextMenuStrip;
                notifyIcon.Icon = (System.Drawing.Icon)TextEimer.Properties.Resources.ResourceManager.GetObject("bucket");
                notifyIcon.Text = "TextEimer";
                notifyIcon.Visible = true;
                notifyIcon.Click += delegate { notifyIconMenu.BuildContextMenuStrip(); };
                NotifyIconSymbol notifyIconSymbol = new NotifyIconSymbol(notifyIcon, notifyIconMenu);
                #endregion

                ClipboardHandler clipboardHandler = new ClipboardHandler(notifyIconMenu);
                clipboardHandler.LogWriter = log;

                #region global Hotkey
                Hotkey hk = new Hotkey();

                hk.KeyCode = Keys.V;
                hk.Windows = true;
                hk.Pressed += delegate {
                    notifyIconSymbol.ShowNotifyIconMenu();
                };

                hk.Register(notifyIconMenu.contextMenuStrip);

                Application.ApplicationExit += delegate {
                    if (hk.Registered)
                    {
                        hk.Unregister();
                    }
                };
                #endregion

                Application.Run();
            }
        }
Exemplo n.º 26
0
        public ProtocolForm()
        {
            InitializeComponent();
            bMutex = new System.Threading.Mutex(false);

            share = new List<string>();
            working = new List<string>();
        }
Exemplo n.º 27
0
 private void AvoidMultiActivate()
 {
     if (mutex.WaitOne(0, false) == true) return;
     log.Debug("Multiple boot detected.");
     mutex.Close();
     mutex = null;
     Shutdown();
 }
 /// <summary>
 ///     LaunchWizardPageBase is the base class for the data source wizard pages that launch Entity Data Model Wizard.
 /// </summary>
 /// <param name="wizard">The wizard that will display the page</param>
 internal LaunchWizardPageBase(DataSourceWizardFormBase wizard)
     : base(wizard)
 {
     _mutex = new ThreadSafeMutex();
     _isPageClosing = false;
     _dismissDSWizard = false;
     InitializeComponent();
 }
Exemplo n.º 29
0
        private static bool IsOneInstance()
        {
            Application.ApplicationExit += Application_ApplicationExit;

            bool one;
            mutex = new System.Threading.Mutex(true, "{585CFBAD-3B6C-413F-88D1-6233310688FE}", out one);
            return one;
        }
Exemplo n.º 30
0
 private void SetupException(int location, WaitHandle handle)
 {
     this.m_MutexIndex = location;
     if (handle != null)
     {
         this.m_Mutex = handle as System.Threading.Mutex;
     }
 }
Exemplo n.º 31
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            bool result;
            var  mutex = new System.Threading.Mutex(true, "SqlReader", out result);

            if (!result)
            {
                if (Environment.UserName.Contains("xception"))
                {
                    MessageBox.Show("Another instance is already running.");
                }
                return;
            }

            try { Application.Run(new Form1()); }catch {}

            GC.KeepAlive(mutex);
        }
Exemplo n.º 32
0
        static void Main()
        {
            try
            {
                bool result;
                using (var mutex = new System.Threading.Mutex(true, Utils.AppName, out result))
                {
                    if (!result)
                    {
                        Utils.MessageBox("Another instance is already running.");
                        return;
                    }

                    Application.Run(new FormLoadGraph());
                }
            }//end try
            catch (Exception err)
            {
                Utils.MessageBox("Main error: " + err.Message);
                Environment.Exit(-1);
            } //end catch
        }     //end Main
Exemplo n.º 33
0
        static void Main(string[] args)
        {
            bool ret;

            System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out ret);
            if (ret)
            {
                if (IPAddressSelector.Instance().ShowDialog() == DialogResult.OK)
                {
                    Application.EnableVisualStyles();
                    Application.DoEvents();
                    Application.ThreadException += Application_ThreadException;
                    AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                    try
                    {
                        IOMonitorManager.CreateConfig();

                        LoginForm form = new LoginForm();
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            //保存配置文件信息
                            IOMonitorManager.Config.WriteConfig();
                            Application.Run(new MonitorForm());
                        }
                    }
                    catch (Exception emx)
                    {
                        MessageBox.Show(emx.Message);
                    }
                    mutex.ReleaseMutex();
                }
            }
            else
            {
                Scada.Controls.Forms.FrmDialog.ShowDialog(null, "有一个和本程序相同的应用程序已经在运行,请不要同时运行多个本程序。\n\n这个程序即将退出。", Application.ProductName);
                //   提示信息,可以删除。
                Application.Exit();//退出程序
            }
        }
Exemplo n.º 34
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            mutex = new System.Threading.Mutex(true, "RankHelper");

            if (mutex.WaitOne(0, false))
            {
                LogHelper.InitLog4Net();
                if (args != null && args.Length > 0) //打印出参数
                {
                    Appinfo.bWork = true;
                }
                Application.Run(new MainForm());
            }
            else
            {
                //MessageBox.Show("程序已经在运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Application.Exit();
            }
        }
Exemplo n.º 35
0
        static void Main()
        {
            AllocConsole();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            bool createNew;

            using (System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out createNew))
            {
                if (createNew)
                {
                    Application.Run(new MainView());
                }
                else
                {
                    MessageBox.Show("应用程序已经在运行中...");
                    System.Threading.Thread.Sleep(1000);
                    System.Environment.Exit(1);
                }
            }
            //Application.Run(new MainView());
        }
Exemplo n.º 36
0
        private void CheckUniqueInstance()
        {
            bool isNew = false;

            uniqueMutex = new System.Threading.Mutex(true, "CrystalUIMutex", out isNew);

            if (!isNew)
            {
                MessageBox.Show("Crystal is already running. If the software is not being displayed please check the system tray (to the bottom right of your screen) for the grey shield icon.",
                                "Crystal is Already Running",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                Process[] procs = Process.GetProcessesByName("CrystalAEPUI");

                if (procs != null && procs.Length != 0)
                {
                    Process  firstProc     = null;
                    DateTime lastStartTime = DateTime.Now;

                    foreach (Process proc in procs)
                    {
                        if (proc.StartTime < lastStartTime)
                        {
                            firstProc     = proc;
                            lastStartTime = proc.StartTime;
                        }
                    }

                    SetForegroundWindow(firstProc.MainWindowHandle);

                    MainUI.ShuttingDownProcess = true;
                    //Application.Exit();
                }

                Environment.Exit(0);
            }
        }
Exemplo n.º 37
0
        static void Main()
        {
            Boolean createdNew;                                                                                            //返回是否赋予了使用线程的互斥体初始所属权

            System.Threading.Mutex instance = new System.Threading.Mutex(true, wapp.SysConfig.SystemName, out createdNew); //同步基元变量
            //赋予了线程初始所属权,也就是首次使用互斥体
            if (!createdNew)
            {
                return;
            }
            //获得当前登录的Windows用户标示
            System.Security.Principal.WindowsIdentity  identity  = System.Security.Principal.WindowsIdentity.GetCurrent();
            System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
            //判断当前登录用户是否为管理员
            if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
            {
                //如果是管理员,则直接运行
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                wapp.SysConfig.NewSysConfig();
                FormLogin fmLogin = new FormLogin();
                Application.Run(fmLogin);
                instance.ReleaseMutex();
            }
            else
            {
                //创建启动对象
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                //设置运行文件
                startInfo.FileName = System.Windows.Forms.Application.ExecutablePath;
                //设置启动动作,确保以管理员身份运行
                startInfo.Verb = "runas";
                //如果不是管理员,则启动UAC
                System.Diagnostics.Process.Start(startInfo);
                //退出
                System.Windows.Forms.Application.Exit();
            }
        }
Exemplo n.º 38
0
        static void Main()
        {
            bool createdNew;

            System.Threading.Mutex m = new System.Threading.Mutex(true, "BxAdapterTodo", out createdNew);
            if (!createdNew)
            {
                Windows wndList = new Windows(false, false);
                foreach (Window wnd in wndList)
                {
                    if (wnd.Title == BxAdapter.BxAdapterTitle)
                    {
                        wnd.Activate();
                    }
                }
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //MUST BE DONE THIS WAY SO HAVE PROPER DEBUGGING ABILITIES
#if DEBUG
            Application.Run(new BxAdapter());
#else
            try
            {
                Application.Run(new BxAdapter());
            }
            catch (Exception e)
            {
                MessageBox.Show("Error: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
#endif

            // keep the mutex reference alive until the normal termination of the program
            GC.KeepAlive(m);
        }
Exemplo n.º 39
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            BonusSkins.Register();

            bool flag = false;

            System.Threading.Mutex hMutex = new System.Threading.Mutex(true, Application.ProductName, out flag);//进程间的同步
            bool b = hMutex.WaitOne(0, false);

            if (!flag)
            {
                MessageBox.Show("当前程序已在运行,请勿重复运行。");
                Environment.Exit(1);//退出程序
            }
            try
            {
                //System.Diagnostics.Process.Start("explorer.exe", AppDomain.CurrentDomain.BaseDirectory);
                LoginFrm loginFrm = new LoginFrm();
                loginFrm.StartPosition = FormStartPosition.CenterScreen;
                loginFrm.ShowDialog();

                if (loginFrm.DialogResult == DialogResult.OK)
                {
                    Application.Run(new FrmMain {
                        WindowState = FormWindowState.Maximized
                    });
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
        }
Exemplo n.º 40
0
        static void Main()
        {
            // Mutex の新しいインスタンスを生成する (Mutex の名前にアセンブリ名を付ける)
            System.Threading.Mutex hMutex = new System.Threading.Mutex(false, Application.ProductName);

            // Mutex のシグナルを受信できるかどうか判断する
            if (hMutex.WaitOne(0, false))
            {
                SetProcessDPIAware();
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                //Application.Run(new Form1());

                // 2020/09/23 会社選択画面
                Common.frmCorpSelect frm = new Common.frmCorpSelect();
                Application.Run(frm);
                string Cpath = Common.Utility.NulltoStr(frm.MyProperty);
                frm.Dispose();

                // 2020/09/23 会社を指定するとメインメニューを表示
                if (Cpath != "")
                {
                    Application.Run(new Form1(Cpath));
                }
            }
            else
            {
                // グローバル・ミューテックスによる多重起動禁止
                MessageBox.Show("このアプリケーションはすでに起動しています。2つ同時には起動できません。", "多重起動禁止");
                return;
            }

            // GC.KeepAlive メソッドが呼び出されるまで、ガベージ コレクション対象から除外される
            GC.KeepAlive(hMutex);

            // Mutex を閉じる (正しくは オブジェクトの破棄を保証する を参照)
            hMutex.Close();
        }
Exemplo n.º 41
0
 static void Main(string[] args)
 {
     try
     {
         bool flag = false;
         System.Threading.Mutex mutex = new System.Threading.Mutex(true, "bingwallpaper", out flag);
         if (flag)
         {
             MyFiles.Init();
             Form_Main fm = new Form_Main();
             if (args.Length > 0)
             {
                 if (args[0] == @"/onekey")
                 {
                     OneKey           = true;
                     fm.Opacity       = 0;
                     fm.ShowInTaskbar = false;
                     fm.Size          = new System.Drawing.Size(1, 1);
                     fm.Opacity       = 0;
                     fm.ShowDialog();
                 }
                 else
                 {
                     OneKey = false;
                     fm.ShowDialog();
                 }
             }
             else
             {
                 fm.ShowDialog();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 42
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            _logger = LogManager.GetLogger(typeof(Program));
            _logger.Info("----- Application Starts -----");
#if !ONLYONE
            bool new_instance;
            using (System.Threading.Mutex mutex = new System.Threading.Mutex(true, "RabNetApplication", out new_instance)) {
                if (new_instance)
                {
#endif
#if !NOCATCH
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Unhandled);
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Threaded);
#endif
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            LoginForm lf = new LoginForm();
            LoginForm.stop = false;
            while (!LoginForm.stop)
            {
                LoginForm.stop = true;
                if (lf.ShowDialog() == DialogResult.OK)
                {
                    Application.Run(new MainForm());
                }
            }
#if !ONLYONE
        }

        else               //new_instance
        {
            SwitchRabWindow();
        }
    }        //using
#endif
        }
Exemplo n.º 43
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            bool requestInitialOwnership = true;

            mut = new System.Threading.Mutex(requestInitialOwnership, "Lemon App", out bool mutexWasCreated);
            if (!(requestInitialOwnership && mutexWasCreated))
            {
                MsgHelper.SendMsg(MsgHelper.SEND_SHOW);
                Current.Shutdown();
            }
            else
            {
                if (!Directory.Exists(Settings.USettings.CachePath))
                {
                    Directory.CreateDirectory(Settings.USettings.CachePath);
                }
                if (!Directory.Exists(Settings.USettings.CachePath + "Skin"))
                {
                    Directory.CreateDirectory(Settings.USettings.CachePath + "Skin");
                }
                new MainWindow().Show();
            }
        }
Exemplo n.º 44
0
        static void Main()
        {
            string version = "453";// !!!! warning  !!!! string needs to be changed with when release version changes

            string ipcChannelPortName = string.Format("RdlProject{0}", version);
            // Determine if an instance is already running?
            bool   firstInstance;
            string mName = string.Format("Local\\RdlDesigner{0}", version);

            //   can't use Assembly in this context
            System.Threading.Mutex mutex = new System.Threading.Mutex(false, mName, out firstInstance);

            if (firstInstance)
            {   // just start up the designer when we're first in line
                Application.EnableVisualStyles();
                Application.DoEvents();
                Application.Run(new RdlDesigner(ipcChannelPortName, true));
                return;
            }

            // Process already running.   Notify other process that is might need to open another file
            string[] args = Environment.GetCommandLineArgs();
        }
Exemplo n.º 45
0
        static void Main()
        {
            //*************************直接启动登陆界面***************************
            //检查当前软件是否已经启动,如果已经启动,提示信息不能重复启动
            bool openExe = false;

            System.Threading.Mutex mm = new System.Threading.Mutex(true, Application.ProductName, out openExe);
            if (!openExe)
            {
                MessageBox.Show("你已经启动该程序!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //显示登陆用户界面
            loginForm = new LoginForm();
            if (loginForm.ShowDialog() == DialogResult.OK)
            {
                Application.Run(new MainForm());
            }
        }
Exemplo n.º 46
0
        static void Main()
        { //是否可以打开新进程
            bool runOne = false;

            //获取程序集Guid作为唯一标识
            Attribute AttGuid  = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(GuidAttribute));
            string    cKeyGuid = ((GuidAttribute)AttGuid).Value;

            mux = new System.Threading.Mutex(true, cKeyGuid, out runOne);
            if (!runOne)
            {
                Environment.Exit(1);
            }
            else
            {
                Xpcom.Initialize(Application.StartupPath + @"\xulrunner");
                INIConfig.setConfigFile(Application.StartupPath + @"\Config.ini");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new frmArea());
                mux.ReleaseMutex();
            }
        }
Exemplo n.º 47
0
        private static void Main()
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                MessageBox.Show("Windows Vista or newer is required.", Application.ProductName);
                return;
            }

            bool isFirstInstance;

            // set if truly first instance:
            var mutex = new System.Threading.Mutex(true, "AeroShot", out isFirstInstance);

            if (!isFirstInstance)
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new SysTray());
            GC.KeepAlive(mutex);
        }
Exemplo n.º 48
0
        private void ButtonRemove_Click(object sender, EventArgs e)
        {
            bool createdNew, success = false;
            var  mutex = new System.Threading.Mutex(true, "XRmonitorsUIUnique", out createdNew);

            if (mutex != null)
            {
                mutex.Dispose();
                mutex   = null;
                success = true;
            }

            if (!success || !createdNew)
            {
                MessageBox.Show("An instance of XRmonitorsUI.exe is still running.  \n\nClose the software before removing it.", "XRmonitors - Still Running");
                return;
            }

            Program.setup_form.remove_progress_panel.Show();
            this.Hide();

            Program.setup_form.remove_progress_panel.Remove();
        }
Exemplo n.º 49
0
        static void Main()
        {
            string mutexName = "{7321D23E-90F9-43F8-8EFD-6423AF969B06}";

            bool grantedOwnership = false;

            System.Threading.Mutex singleInstanceMutex = new System.Threading.Mutex(true, mutexName, out grantedOwnership);
            try
            {
                if (!grantedOwnership)
                {
                    return;
                }
                else
                {
                    Application.Run(new AppContext());
                }
            }
            finally
            {
                singleInstanceMutex.Close();
            }
        }
Exemplo n.º 50
0
        public static bool Init()
        {
            Log.Write("Initializing App");
            bool ok;

            oSingleInstance = new System.Threading.Mutex(true, "MuMonitor_", out ok);

            if (!ok)
            {
                // Another instance is already running. Exit
                System.Windows.MessageBox.Show("Another instance of MuMonitor already running.", "MuMonitor");
                System.Windows.Application.Current.Shutdown();
            }

            if (isConnected())
            {
                return(true);
            }

            m_client = new HttpClient();

            return(true);
        }
        static void Main()
        {
            //Verifica se o aplicativo já esta aberto, se estiver não abre novamente

            var identificadorMutex = string.Format("{0}_{1}", "A403A6EB-6472-4B42-B5C1-C0E06F9F2SGV", System.Security.Principal.WindowsIdentity.GetCurrent().User);

            using (var mutex = new System.Threading.Mutex(true, identificadorMutex))
            {
                var jaEstaRodando = !mutex.WaitOne(0, true);
                if (jaEstaRodando)
                {
                    MessageBox.Show("O aplicativo SGV - Sistema de Gestão em Vendas já está sendo executado. Feche o que está aberto para iniciar novamente, ou reinicie seu computador que o problema será resolvido.", "Aviso!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Application.Exit();
                    return;
                }
                //APRESENTACAO.Conexao.CriaStringConexao();
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new FrmSplash());

                mutex.ReleaseMutex();
            }
        }
Exemplo n.º 52
0
        public static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                ConsoleWrapper.WriteLine(args[0]);
            }

            string appGuid = System.Runtime.InteropServices.Marshal
                             .GetTypeLibGuidForAssembly(System.Reflection.Assembly.GetExecutingAssembly()).ToString();
            var nonExisted = false;

            var mtx = new System.Threading.Mutex(true, appGuid, out nonExisted);

            if (!nonExisted)
            {
                ConsoleWrapper.ShowError("Application already runs!");
                System.Threading.Thread.Sleep(3000);
                return;
            }

            OnStartUp.Load();
            UserInterface.Run(args);
        }
Exemplo n.º 53
0
        void App_Startup(object sender, StartupEventArgs e)
        {
            bool ret;

            try
            {
                mutex = new System.Threading.Mutex(true, "iVend", out ret);

                if (!ret)
                {
                    // 程序已经打开
                    Environment.Exit(0);
                }
            }
            catch
            {
                System.Windows.Application.Current.Shutdown();
                System.Reflection.Assembly.GetEntryAssembly();
                string startpath = System.IO.Directory.GetCurrentDirectory();
                System.Diagnostics.Process.Start(startpath + "/iVend.exe"); //xxxx.exe为要启动的程序
                ////Environment.Exit(0);
            }
        }
Exemplo n.º 54
0
        static void Main()
        {
            //是否可以打开新进程(用于在一台电脑中只能运行唯一实例的场合)
            bool createNew;

            //获取程序集Guid作为唯一标识
            Attribute guid_attr = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(GuidAttribute));
            string    guid      = ((GuidAttribute)guid_attr).Value;

            appMutex = new System.Threading.Mutex(true, guid, out createNew);

            if (false == createNew)
            {
                //发现重复进程
                return;
            }

            appMutex.ReleaseMutex();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new solingScrew());
        }
Exemplo n.º 55
0
        static void Main()
        {
            bool mutexCreated = false;

            System.Threading.Mutex appMutex = new System.Threading.Mutex(false, AppMutexName, out mutexCreated);
            //You could abort here if the mutex existed already, or you could abort
            //when failing to acquire the mutex. I prefer the latter.
            if (!appMutex.WaitOne(0))
            {
                //MessageBox.Show("Only one application at a time, please!");
                return;
            }
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new SplashScreen());
            }
            finally
            {
                appMutex.ReleaseMutex();
            }
        }
Exemplo n.º 56
0
        static void Main(string[] args)
        {
            bool isrun;

            System.Threading.Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out isrun);
            if (isrun)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);


                if (args.Length > 0)
                {
                    Application.Run(new QrUserCode(args[0]));
                }
                else
                {
                    Application.Exit();
                }
                mutex.ReleaseMutex();
            }
            SetForegroundWindow(Process.GetProcessesByName(Application.ProductName)[0].MainWindowHandle);            //放到前端
        }
Exemplo n.º 57
0
        private void App_Startup(object sender, StartupEventArgs e)
        {
            bool ret;

            mutex = new System.Threading.Mutex(true, "MinFrm", out ret);

            if (!ret)
            {
                MessageBox.Show("已有一个客户端正在运行,请先结束原来客户端!");
                Environment.Exit(0);
            }
            #region 设置程序开机自动运行(+注册表项)
            try
            {
                SetSelfStarting(false, "MinFrm.exe");
            }
            catch (Exception ex)
            {
                WriteLog(ex);
            }

            #endregion
        }
        static void Main(string[] args)
        {
            bool result;
            var  mutex = new System.Threading.Mutex(true, "f49da1b0-6675-4ecd-ad39-fd2172b545fc", out result);

            if (!result)
            {
                MessageBox.Show("Another instance of DNS updater is already running.");
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (args.Length != 0)
            {
                Application.Run(new Form1(args[0]));
            }
            else
            {
                Application.Run(new Form1("normalState"));
            }
            GC.KeepAlive(mutex);
        }
Exemplo n.º 59
0
        static void Main()
        {
            Boolean createdNew;

            System.Threading.Mutex instance = new System.Threading.Mutex(true, "CachongSingleStart0.8", out createdNew); //同步基元变量
            if (createdNew)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                try
                {
                    Application.Run(new Form1());
                    instance.ReleaseMutex();
                }
                catch (Exception)
                { }
            }
            else
            {
                MessageBox.Show("已经存在一个正在运行的查重程序!");
                Application.Exit();
            }
        }
Exemplo n.º 60
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            mutex = new System.Threading.Mutex(true, "OnlyRun");
            if (mutex.WaitOne(0, false))
            {
                Application.Run(new LoginForm());
                //Application.Run(new MainForm());

                //Application.Run(new Forms.Loading());
                //Application.Run(new Forms.FindCount());
                //Application.Run(new MainForm());
                //Application.Run(new MainForm());
                //Application.Run(new MainForm());
                //Application.Run(new MainForm());
            }
            else
            {
                MessageBox.Show("程序已经在运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Application.Exit();
            }
        }