C#
[C#/PDA]PDA 프로그램 중복 실행 방지 예제
선영아 사랑해
2016. 1. 21. 14:08
.net Compact Framework에서 프로그램을 개발하다보면 API를 이용해야 하는 경우가 자주 발생합니다.
그럴때 마다 구글에서 검색하는 것도 만만치 않은 일입니다.
그런 고민을 해결하고자 아래와 같은 API 및 함수를 만들었으니 개발할때 참고하세요.
[DllImport("coredll.dll", EntryPoint = "CreateMutex", SetLastError = true)]
static extern IntPtr CreateMutex(int lpMutexAttributes, bool InitialOwner, string MutexName);
[DllImport("coredll.dll", EntryPoint = "ReleaseMutex", SetLastError = true)]
static extern bool ReleaseMutex(IntPtr hMutex);
//중복 실행 확인
public bool ProcessStartCheck(string processname)
{
IntPtr h = CreateMutex(0, true, processname);
if (h == IntPtr.Zero)
{
return false;
}
else
{
return true;//이미 실행 중
}
}