本文整理汇总了C#中System.Threading.Mutex.WaitOne方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.Mutex.WaitOne方法的具体用法?C# System.Threading.Mutex.WaitOne怎么用?C# System.Threading.Mutex.WaitOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Mutex
的用法示例。
在下文中一共展示了System.Threading.Mutex.WaitOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
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が起動されています。" );
}
}
}
示例2: Main
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();
}
}
示例3: CheckPrevious
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;
}
}
示例4: 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;
}
}
}
示例5: Main
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();
}
}
示例6: 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;
}
}
}
示例7: App
public App()
: base()
{
mutex = new System.Threading.Mutex(false, "MutexForMinidamWorking");
if(!mutex.WaitOne(0))
{
// すでに起動している
Shutdown();
}
}
示例8: 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();
}
示例9: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//防止启动多个实例.
mutex = new System.Threading.Mutex(true, "ZJUWLAN001");
if (mutex.WaitOne(0, false))
{
Application.Run(new frmWLANLogin());
}
}
示例10: Form1
public Form1()
{
InitializeComponent();
SetFormats();
mutex = new System.Threading.Mutex(false, "FAMILTSDSERVER");
if (!mutex.WaitOne(0, false))
{
mutex.Close();
mutex = null;
}
}
示例11: Main
static void Main()
{
using (System.Threading.Mutex mutex = new System.Threading.Mutex(false, Application.ProductName))
{
if (mutex.WaitOne(0, false))
{
int hModule = LoadLibrary(@"Injection.dll");
if (hModule == 0)
{
MessageBox.Show("error:LoadLibrary failed.");
return;
}
IntPtr intPtrInstall = GetProcAddress(hModule, @"InstallHook");
IntPtr intPtrRemove = GetProcAddress(hModule, @"RemoveHook");
if (intPtrInstall == null)
{
MessageBox.Show("error:InstallHook function is not included in Core.dll.");
FreeLibrary(hModule);
return;
}
if (intPtrRemove == null)
{
MessageBox.Show("error:intPtrRemove function is not included in Core.dll.");
FreeLibrary(hModule);
return;
}
HOOKFUNC InstallHook =
(HOOKFUNC)Marshal.GetDelegateForFunctionPointer
(intPtrInstall, typeof(HOOKFUNC));
HOOKFUNC RemoveHook =
(HOOKFUNC)Marshal.GetDelegateForFunctionPointer
(intPtrRemove, typeof(HOOKFUNC));
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
InstallHook();
using (new MainForm())
{
Application.Run();
}
RemoveHook();
FreeLibrary(hModule);
}
}
}
示例12: Main
static void Main()
{
System.Threading.Mutex mu = new System.Threading.Mutex(false, "mutex demo");
if (!mu.WaitOne(TimeSpan.FromSeconds(1), false))
{
MessageBox.Show("already running...");
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LiveCamera());
}
示例13: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
mutex = new System.Threading.Mutex(true, "LuckOnlyRun");
if (mutex.WaitOne(0, false))
{
Application.Run(new LuckForm());
}
else
{
Application.Exit();
}
}
示例14: Main
static void Main()
{
var mutex = new System.Threading.Mutex( false, Application.ExecutablePath.Replace( '\\', '/' ) );
if ( !mutex.WaitOne( 0, false ) ) {
// 多重起動禁止
MessageBox.Show( "既に起動しています。\r\n多重起動はできません。", "七四式電子観測儀", MessageBoxButtons.OK, MessageBoxIcon.Error );
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new FormMain() );
mutex.ReleaseMutex();
}
示例15: Main
static void Main() {
var mutex = new System.Threading.Mutex( false, Application.ExecutablePath.Replace( '\\', '/' ) );
if ( !mutex.WaitOne( 0, false ) ) {
// 多重起動禁止
MessageBox.Show( Properties.Resources.SoftwareName + Properties.Resources.Version + Properties.Resources.NoMultipleStart, Properties.Resources.SoftwareName + Properties.Resources.Version, MessageBoxButtons.OK, MessageBoxIcon.Error );
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new FormMain() );
mutex.ReleaseMutex();
}