using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
//using System.Diagnostics;
//using System.Reflection;
//using System.Runtime.InteropServices;
namespace WindowsApplication1
{
///
/// Form1 の概要の説明です。
///
public class Form1 : System.Windows.Forms.Form
{
///
/// 必要なデザイナ変数です。
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows フォーム デザイナ サポートに必要です。
//
InitializeComponent();
}
///
/// 使用されているリソースに後処理を実行します。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows フォーム デザイナで生成されたコード
///
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
///
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(142, 116);
this.Name = "Form1";
this.Text = "Form1";
}
#endregion
// アプリケーション固定名
private static string strAppConstName = "daSampleApp";
// 多重起動を防止するミューテックス
private static Mutex mutexObject;
///
/// アプリケーションのメイン エントリ ポイントです。
///
[STAThread]
static void Main()
{
// Windows 2000(NT 5.0)以降のみグローバル・ミューテックス利用可
OperatingSystem os = Environment.OSVersion;
if ((os.Platform == PlatformID.Win32NT) && (os.Version.Major >= 5))
{
strAppConstName = @"Global\" + strAppConstName;
}
try
{
// ミューテックスを生成する
mutexObject = new Mutex(false, strAppConstName);
}
catch (ApplicationException e)
{
// グローバル・ミューテックスの多重起動防止
MessageBox.Show("すでに起動しています。2つ同時には起動できません。", "多重起動防止");
return;
}
// ミューテックスを取得する
if (mutexObject.WaitOne(0, false))
{
// アプリケーションを実行
Application.Run(new Form1());
// ミューテックスを解放する
mutexObject.ReleaseMutex();
}
else
{
// 警告を表示して終了
MessageBox.Show("すでに起動しています。2つ同時には起動できません。", "多重起動防止");
}
// ミューテックスを破棄する
mutexObject.Close();
}
}
}