当前位置: 首页>>代码示例>>C#>>正文


C# System.Threading.Mutex.Close方法代码示例

本文整理汇总了C#中System.Threading.Mutex.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.Mutex.Close方法的具体用法?C# System.Threading.Mutex.Close怎么用?C# System.Threading.Mutex.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.Mutex的用法示例。


在下文中一共展示了System.Threading.Mutex.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        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();
        }
开发者ID:reednj,项目名称:TimeTrack,代码行数:27,代码来源:Program.cs

示例2: Main

        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();
        }
开发者ID:scott-t,项目名称:iMote,代码行数:25,代码来源:Program.cs

示例3: Main

        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;
                }
            }

        }
开发者ID:Andrew414,项目名称:OLOLAPReport,代码行数:28,代码来源:Program.cs

示例4: Main

        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);
            }
        }
开发者ID:ifidakov,项目名称:trunk,代码行数:27,代码来源:Program.cs

示例5: Main

        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var appSingleton = new System.Threading.Mutex(false, "SingleInstance WinMoreNSnap");
            if (appSingleton.WaitOne(0, false))
                Application.Run(new TrayApp());
            appSingleton.Close();
        }
开发者ID:elcado,项目名称:WinMoreNSnap,代码行数:10,代码来源:Program.cs

示例6: Form1

        public Form1()
        {
            InitializeComponent();
            SetFormats();

            mutex = new System.Threading.Mutex(false, "FAMILTSDSERVER");
            if (!mutex.WaitOne(0, false))
            {
                mutex.Close();
                mutex = null;
            }
        }
开发者ID:ramilexe,项目名称:tsdfamilia,代码行数:12,代码来源:Form1.cs

示例7: Application_Startup

        /// <summary>アプリケーション初期化処理</summary>
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // 二重起動禁止
            _mutex = new System.Threading.Mutex(false, Application.ResourceAssembly.FullName);
            if (!_mutex.WaitOne(0, false))
            {
                _mutex.Close();
                _mutex = null;
                this.Shutdown();
            }

            // 開始
            Start();

            // 終了
            Shutdown();
        }
开发者ID:hirekoke,项目名称:FloWin,代码行数:18,代码来源:App.xaml.cs

示例8: Main

        static void Main(string[] args)
        {
            bool createdNew;
            System.Threading.Mutex m = new System.Threading.Mutex(true, "avalon_gui_ever", out createdNew);

            int usbCount = 0;
            if (args != null && args.Length >= 2)
            {
                if (args[0] == "-n")
                {
                    int v = 0;
                    if (Int32.TryParse(args[1], out v))
                    {
                        if (v < 0)
                        {
                            v = 0;
                        }

                        usbCount = v;
                    }
                }
            }

            try
            {
                if (!createdNew)
                {
                    return;
                }

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

                MainForm mainForm = new MainForm();
                mainForm.SetUSBCount(usbCount);
                Application.Run(mainForm);
            }
            finally
            {
                m.Close();
                ProcessKiller.KillProcessByName(Constants.BfgMinerFileName);
            }
        }
开发者ID:peterwillcn,项目名称:Avalon-nano,代码行数:43,代码来源:Program.cs

示例9: Main

        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            // Mutex の新しいインスタンスを生成する (Mutex の名前にアセンブリ名を付ける)
            System.Threading.Mutex hMutex = new System.Threading.Mutex(false, Application.ProductName);

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

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

            // Mutex を閉じる (正しくは オブジェクトの破棄を保証する を参照)
            hMutex.Close();
        }
开发者ID:kambara,项目名称:PileDesktopServer,代码行数:20,代码来源:Program.cs

示例10: Form1

        //bool EraseTerminalDB = false;
        

        public Form1()
        {
            InitializeComponent();
            //SetFormats();

            mutex = new System.Threading.Mutex(false, "FAMILTSDSERVER");
            if (!mutex.WaitOne(0, false))
            {
                mutex.Close();
                mutex = null;
            }
            loader.OnProcessImport += new DataLoaderClass.ProcessImport(Form1_OnProcessImport);
            loader.OnFinishImport += new DataLoaderClass.FinishImport(Form1_OnFinishImport);
            loader.OnFailedImport += new DataLoaderClass.FailedImport(Form1_OnFailedImport);

            //productAdapter =
            //          new TSDServer.ProductsDataSetTableAdapters.ProductsTblTableAdapter(this.productsDataSet1);

            //docsAdapter =
            //    new TSDServer.ProductsDataSetTableAdapters.DocsTblTableAdapter(this.productsDataSet1);
        }
开发者ID:ramilexe,项目名称:tsdfamilia,代码行数:24,代码来源:Form1.cs

示例11: Main

 static void Main(string[] args)
 {
     System.Threading.Mutex mutex = new System.Threading.Mutex(false, Application.ProductName);
     if (mutex.WaitOne(0, false) == false) return;
     if (args.Length > 0)
     {
         if (args[0].ToLower().Trim().Substring(0, 2).Equals("/s"))
         {
             //Show
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             ShowScreenSaver();
             Application.Run();
         }
         if (args[0].ToLower().Trim().Substring(0, 2).Equals("/p"))
         {
             //Preview
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             Application.Run(new MainForm(new IntPtr(long.Parse(args[1]))));
         }
         if (args[0].ToLower().Trim().Substring(0, 2).Equals("/c"))
         {
             //Config
             MessageBox.Show("オプションなし\nこのスクリーンセーバーには、設定できるオプションはありません。", "LifeGame ScreenSaver");
         }
     }
     else
     {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         ShowScreenSaver();
         Application.Run();
     }
     GC.KeepAlive(mutex);
     mutex.Close();
 }
开发者ID:remew,项目名称:LifeGameScreenSaver,代码行数:37,代码来源:Program.cs

示例12: Main

        public static void Main()
        {
            // Windows 2000�iNT 5.0�j�ȍ~�̂݃O���[�o���E�~���[�e�b�N�X���p��
            OperatingSystem os = Environment.OSVersion;

            if ((os.Platform == PlatformID.Win32NT) && (os.Version.Major >= 5))
            {
                mutexName = @"Global\" + mutexName;
            }

            try
            {
                // �~���[�e�b�N�X�𐶐�����
                mutexObject = new System.Threading.Mutex(false, mutexName);
            }
            catch (ApplicationException)
            {
                return;
            }

            // �~���[�e�b�N�X��擾����
            if (mutexObject.WaitOne(0, false))
            {
                // �A�v���P�[�V��������s
                using (PSUTools main = new PSUTools())
                {
                    Application.Run();
                }

                // �~���[�e�b�N�X��������
                mutexObject.ReleaseMutex();
            }

            // �~���[�e�b�N�X��j������
            mutexObject.Close();
        }
开发者ID:saasan,项目名称:PSUTools,代码行数:36,代码来源:PSUTools.cs

示例13: _CompileSource

        System.Reflection.Assembly _CompileSource(string Input, bool InputIsFile, bool exe, string outputname)
        {
            string[] asmrefs = new string[AssemblyReferences.Count];
            List<string> assemblydirs = new List<string>();
            char[] slashes = new char[] { '/', '\\' };
            for (int i = 0; i < asmrefs.Length; i++)
            {
                string ar = AssemblyReferences[i];
                int ils = ar.LastIndexOfAny(slashes);
                if (-1 != ils)
                {
                    assemblydirs.Add(ar.Substring(0, ils));
                    ar = ar.Substring(ils + 1);
                }
                asmrefs[i] = ar;
            }
            StringBuilder localcompileropts = new StringBuilder();
            {
                for (int i = 0; i < assemblydirs.Count; i++)
                {
                    localcompileropts.Append(" /lib:\"" + assemblydirs[i] + "\"");
                }
            }
            System.CodeDom.Compiler.CompilerParameters cp = new System.CodeDom.Compiler.CompilerParameters(asmrefs);
            cp.IncludeDebugInformation = _compilerdbg;
            System.CodeDom.Compiler.CompilerResults cr = null;
            bool alreadylogged = false;
            string reason = "";
            for (int rotor = 1; ; rotor++)
            {
#if DEBUG
                if (rotor > 3)
                {
                    throw new System.IO.FileNotFoundException("ArrayComboList.CompileSource dynamic C# compilation: Unable to create DLL" + reason);
                }
#endif
                try
                {
                    cp.OutputAssembly = outputname;
                    cp.GenerateExecutable = exe;
                    cp.GenerateInMemory = false;
                    cp.CompilerOptions = getcompileropts() + localcompileropts.ToString();

                    {
                        System.Threading.Mutex mdc = new System.Threading.Mutex(false, "DynCmp");
                        try
                        {
                            mdc.WaitOne();
                        }
                        catch (System.Threading.AbandonedMutexException)
                        {
                        }
                        try
                        {
                            Dictionary<string, string> providerOptions = new Dictionary<string, string>();
                            providerOptions["CompilerVersion"] = "v3.5";
                            using (Microsoft.CSharp.CSharpCodeProvider cscp = new Microsoft.CSharp.CSharpCodeProvider(providerOptions))
                            {
                                if (InputIsFile)
                                {
                                    cr = cscp.CompileAssemblyFromFile(cp, Input);
                                }
                                else
                                {
                                    cr = cscp.CompileAssemblyFromSource(cp, Input);
                                }
                            }
                        }
                        finally
                        {
                            mdc.ReleaseMutex();
                            mdc.Close();
                        }
                    }
                    if (cr.Errors.HasErrors)
                    {
                        try
                        {
                            lock (typeof(Compiler))
                            {
                                if (InputIsFile)
                                {
                                    System.IO.File.Copy(Input, "error.cs", true); // overwrite=true
                                }
                                else
                                {
                                    System.IO.File.WriteAllText("error.cs", Input);
                                }
                            }
                        }
                        catch
                        {
                        }
                        for (int i = 0; i < cr.Errors.Count; i++)
                        {
                            if (!cr.Errors[i].IsWarning)
                            {
                                throw new Exception("CompileSource code compile error: " + cr.Errors[i].ToString());
                            }
                        }
//.........这里部分代码省略.........
开发者ID:erisonliang,项目名称:qizmt,代码行数:101,代码来源:Compiler.cs

示例14: Main

 static void Main()
 {
     bool newmutex = false;
     mutex = new System.Threading.Mutex(true, "MouseLiner", out newmutex);
     if(newmutex) {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         //
         InitializeComponent();
         //
         Application.Run();
     }
     mutex.Close();
 }
开发者ID:kobachi,项目名称:MouseLiner,代码行数:14,代码来源:Program.cs

示例15: Main

        static void Main()
        {
            string assName = System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location);
            System.Threading.Mutex mutex = new System.Threading.Mutex(false, assName);
            try
            {
                if (mutex.WaitOne(0, false))
                {
                    // Run the application
                    string applicationName = ConfigurationManager.AppSettings["LoggerAppName"];
                    LoggerExtensionUtils.InitLogger(applicationName);
                    LoggerExtensionUtils.FromEmail = ConfigurationManager.AppSettings["MailFrom"].Decrypt();
                    LoggerExtensionUtils.DeveloperEmail = ConfigurationManager.AppSettings["MailDeveloper"].Decrypt();

                    MethodBase.GetCurrentMethod().Info("************** " + applicationName + " - START");

                    // Registering all dependency injection objects
                    Bootstrapper.Wire(new DependencyInjectionModul());

                    // Configure AutoMapper
                    AutoMapperConfiguration.Configure();

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

                        DevExpress.Skins.SkinManager.EnableFormSkins();
                        DevExpress.UserSkins.BonusSkins.Register();
                        XtraMessageBox.AllowCustomLookAndFeel = true;
                        UserLookAndFeel.Default.SetSkinStyle("DevExpress Style");

                        SplashScreenManager.ShowForm(typeof(StartupScreen), true, true);

                        Application.Run(FormHelpers.CurrentMainForm);
                        MethodBase.GetCurrentMethod().Info("************** " + applicationName + " - END");
                    }
                    catch (Exception ex)
                    {
                        MethodBase.GetCurrentMethod().Error("Unable to initialize database!", ex);
                        XtraMessageBoxHelper.ShowError(null, "Aplikasi error! Mohon hubungi developer.");
                        MethodBase.GetCurrentMethod().Info("************** " + applicationName + " - END");
                    }
                }
                else
                {
                    MessageBox.Show("Aplikasi MIS Brawijaya sudah berjalan", "Pemberitahuan");
                }
            }
            finally
            {
                if (mutex != null)
                {
                    mutex.Close();
                    mutex = null;
                }
            }
        }
开发者ID:edwinsyarief,项目名称:Brawijaya-Workshop-Solution,代码行数:58,代码来源:Program.cs


注:本文中的System.Threading.Mutex.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。