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


C# Mutex.Close方法代码示例

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


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

示例1: Main

	static void Main ()
	{
		// allow only one instance of the process
		Mutex onlyOne = new Mutex (true, "bug349680");

		if (onlyOne.WaitOne (0, false)) {
			try {
				new Program ();
			} finally {
				onlyOne.Close ();
				onlyOne = null;
			}
		}
	}
开发者ID:mono,项目名称:gert,代码行数:14,代码来源:test.cs

示例2: GetLoadBalancer

  // Methods
  public static LoadBalancer GetLoadBalancer()
  {
    // Support multithreaded applications through
    // "Double checked locking" pattern which avoids 
    // locking every time the method is invoked
    if( balancer == null )
    {
      // Only one thread can obtain a mutex
      Mutex mutex = new Mutex();
      mutex.WaitOne();

      if( balancer == null )
        balancer = new LoadBalancer();

      mutex.Close();
    }
    
    return balancer;
  }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:20,代码来源:Singleton_RealWorld.cs

示例3: Main


//.........这里部分代码省略.........
                    {
                        if (
                            MessageBox.Show("Reset iSpy? This will overwrite all your settings.", "Confirm",
                                            MessageBoxButtons.OKCancel) == DialogResult.OK)
                            EnsureInstall(true);
                    }
                    else
                    {
                        MessageBox.Show("Please exit iSpy before resetting it.");
                    }
                }
                if (args[0].ToLower().Trim() == "-silent" || args[0].ToLower().Trim('\\') == "s")
                {
                    if (firstInstance)
                    {
                        silentstartup = true;
                    }
                }
                else
                {
                    command = args.Aggregate(command, (current, s) => current + (s + " "));
                }
            }

            if (!firstInstance)
            {
                if (!string.IsNullOrEmpty(command))
                {
                    File.WriteAllText(AppDataPath + "external_command.txt", command);
                    Thread.Sleep(1000);
                }
                else
                {
                    //show form
                    File.WriteAllText(AppDataPath + "external_command.txt", "showform");
                    Thread.Sleep(1000);
                }
                
                Application.Exit();
                return;
            }

            if (IntPtr.Size == 8)
                Platform = "x64";

            File.WriteAllText(AppDataPath + "external_command.txt", "");

            // in case our https certificate ever expires or there is some other issue
            ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
            ServicePointManager.Expect100Continue = false;
            ServicePointManager.DefaultConnectionLimit = 1000;

            FfmpegMutex = new Mutex();
            
            Application.ThreadException += ApplicationThreadException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
            
            var ffmpegSetup = new Init();
            ffmpegSetup.Initialise();

            _previousExecutionState = NativeCalls.SetThreadExecutionState(NativeCalls.EsContinuous | NativeCalls.EsSystemRequired);
            
            AppIdle = new WinFormsAppIdleHandler {Enabled = false};
            var mf = new MainForm(silentstartup, command);
            Application.Run(mf);
            FfmpegMutex.Close();

            GC.KeepAlive(FfmpegMutex);
            AppIdle.Enabled = false;
            ffmpegSetup.DeInitialise();
            

            if (_previousExecutionState != 0)
            {
                NativeCalls.SetThreadExecutionState(_previousExecutionState);
            }
            
        }
        catch (Exception ex)
        {
            try
            {
                Logger.LogExceptionToFile(ex);
            } catch
            {
                
            }
            while (ex.InnerException != null)
            {
                try
                {
                    Logger.LogExceptionToFile(ex);
                }
                catch
                {

                }
            }
        }
    }
开发者ID:tdhieu,项目名称:iSpy,代码行数:101,代码来源:Program.cs

示例4: Main


//.........这里部分代码省略.........

            string executableName = Application.ExecutablePath;
            var executableFileInfo = new FileInfo(executableName);
            ExecutableDirectory = executableFileInfo.DirectoryName;

            bool ei = (!Directory.Exists(AppDataPath) || !Directory.Exists(AppDataPath + @"XML\") ||
                       !File.Exists(AppDataPath + @"XML\config.xml"));
            if (ei)
                EnsureInstall(true);

            bool silentstartup = false;

            string command = "";
            if (args.Length > 0)
            {
                //if (args[0].ToLower().Trim() == "-firstrun" && !ei)
                //    EnsureInstall(false);
                if (args[0].ToLower().Trim() == "-reset" && !ei)
                {
                    if (firstInstance)
                    {
                        if (
                            MessageBox.Show("Reset iSpy? This will overwrite all your settings.", "Confirm",
                                            MessageBoxButtons.OKCancel) == DialogResult.OK)
                            EnsureInstall(true);
                    }
                    else
                    {
                        MessageBox.Show("Please exit iSpy before resetting it.");
                    }
                }
                if (args[0].ToLower().Trim() == "-silent" || args[0].ToLower().Trim('\\') == "s")
                {
                    if (firstInstance)
                    {
                        silentstartup = true;
                    }
                }
                else
                {
                    for (int index = 0; index < args.Length; index++)
                    {
                        string s = args[index];
                        command += s + " ";
                    }
                }
            }

            if (!firstInstance)
            {
                if (!String.IsNullOrEmpty(command))
                {
                    File.WriteAllText(AppDataPath + "external_command.txt", command);
                    //ensures pickup by filesystemwatcher
                    Thread.Sleep(1000);
                }

                Application.Exit();
                return;
            }

            if (VlcHelper.VlcInstalled)
                VlcHelper.AddVlcToPath();

            File.WriteAllText(AppDataPath + "external_command.txt", "");

            // in case our https certificate ever expires or there is some other issue
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            WriterMutex = new Mutex();
            Application.ThreadException += ApplicationThreadException;

            var mf = new MainForm(silentstartup, command);
            Application.Run(mf);
            WriterMutex.Close();
            WriterMutex.Dispose();

        }
        catch (Exception ex)
        {
            try
            {
                Log.Error("",ex);//MainForm.LogExceptionToFile(ex);
            } catch
            {

            }
            while (ex.InnerException != null)
            {
                try
                {
                    Log.Error("",ex);//MainForm.LogExceptionToFile(ex);
                }
                catch
                {

                }
            }
        }
    }
开发者ID:vmail,项目名称:main,代码行数:101,代码来源:Program.cs

示例5: ThreadFunc

        static void ThreadFunc()
        {
            bool bCreated = false;
            var user = "gordonlee";
            var rule = new MutexAccessRule(user, MutexRights.FullControl, AccessControlType.Allow );
            var mSecurity = new MutexSecurity();
            mSecurity.AddAccessRule(rule);
            
            Mutex m = new Mutex(true, Program.mutex_name, out bCreated, mSecurity);
            if (!bCreated)
            {
                Console.WriteLine("Waiting... {0}", Thread.CurrentThread.ManagedThreadId);
                m.WaitOne();
                Console.WriteLine("Acquired Mutex! {0}", Thread.CurrentThread.ManagedThreadId);
            }

            System.Threading.Thread.Sleep(5 * 1000);

            m.ReleaseMutex();

            m.Close();

        }
开发者ID:gordonlee,项目名称:testlab,代码行数:23,代码来源:Program.cs


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