상세 컨텐츠

본문 제목

C# Application 하나만 실행되게.

C#

by 탑~! 2012. 3. 6. 13:27

본문


[DllImport("user32.dll")] 
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
bool createdNew = true;
using (Mutex mutex = new Mutex(true, "MyApplicationName", out createdNew))
{
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
else
{
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
SetForegroundWindow(process.MainWindowHandle);
break;
}
}
}
}
}

'C#' 카테고리의 다른 글

http://kongmks.blog.me/10012352792  (0) 2012.03.10
Ping Source  (0) 2012.03.06
문자열 수식 계산기  (0) 2012.03.02
Sample Entity Framework Provider For Oracle  (0) 2012.02.29
Windows Service 만들기  (0) 2012.02.28

관련글 더보기