// ProcessMutex.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" #include "Form1.h" using namespace ProcessMutex; using namespace System; [STAThreadAttribute] int main(array ^args) { // Mutex の新しいインスタンスを生成する (Mutex の名前にアセンブリ名を付ける) System::Threading::Mutex^ hMutex = gcnew System::Threading::Mutex(false, Application::ProductName); // Mutex のシグナルを受信できるかどうか判断する if (hMutex->WaitOne(0, false)) { // メイン ウィンドウを作成して、実行します Application::Run(gcnew Form1()); } // GC.KeepAlive メソッドが呼び出されるまで、ガベージ コレクション対象から除外される GC::KeepAlive(hMutex); // Mutex を閉じる hMutex->Close(); return 0; }