本文整理汇总了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;
}
}
}
示例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;
}
示例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
{
}
}
}
}
示例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
{
}
}
}
}
示例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();
}