๋ฐฉ๋ฒ 1. ํ๋ก์ธ์ค ์ด๋ฆ ์ค๋ณต ๊ฐ์ง
//์ด๋ฏธ ํ๋ก๊ทธ๋จ์ด ์คํ ์ค ์ผ๋...
System.Diagnostics.Process[] processes = null;
string strCurrentProcess = System.Diagnostics.Process.GetCurrentProcess().ProcessName.ToUpper();
processes = System.Diagnostics.Process.GetProcessesByName(strCurrentProcess);
if (processes.Length > 1)
{
MessageBox.Show(string.Format("'{0}' ํ๋ก๊ทธ๋จ์ด ์ด๋ฏธ ์คํ ์ค์
๋๋ค.", System.Diagnostics.Process.GetCurrentProcess().ProcessName));
Application.Exit();
}
์ถ์ฒ:
https://kdsoft-zeros.tistory.com/m/45
[C#] ํ๋ก๊ทธ๋จ ์ค๋ณต ์คํ ๋ฐฉ์ง
* ํ๋ก๊ทธ๋จ ์ค๋ณต ์คํ ๋ฐฉ์ง ์์ 1. Visual Studio ๋ฅผ ์ผ๊ณ ๋ฉ๋ด์์ ํ์ผ -> ์๋ก ๋ง๋ค๊ธฐ -> Project ๋ฅผ ์ ํ C# Windows Forms ์์ฉ ํ๋ก๊ทธ๋จ ์ด์ด ์ค๋๋ค. 2. ์๋์ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ์ค๋ฅธ์ชฝ ์๋ฃจ์ ํ์๊ธฐ์
kdsoft-zeros.tistory.com
๋ฐฉ๋ฒ 2. mutex ์ค๋ณต ๊ฐ์ง
๋ฎคํ ์ค(mutex)๋ ์ํธ ๋ฐฐ์ (mutual exclusion)์ ์ฝ์๋ก ํ๋ก์ธ์ค๋ ์ค๋ ๋๋ฑ์ด ๋์์ ์ ๊ทผํด์๋ ์๋๋ ๊ณต์ ์์ญ์ ๋ปํฉ๋๋ค.
bool flagMutex;
System.Threading.Mutex m_hMutex = new System.Threading.Mutex(true, "TestFrm", out flagMutex);
if (flagMutex)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// ์คํํ Form ํด๋์ค
Application.Run(new Form1());
m_hMutex.ReleaseMutex();
}
else
{
// ์ฌ๋ฌ๊ฐ ์คํ์์ผฐ์๋ ๋์ธ ๋ฉ์์ง
MessageBox.Show("ํ๋ก๊ทธ๋จ์ด ์ด๋ฏธ ์คํ ์ค์
๋๋ค", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
์ถ์ฒ:
https://backyarddev.tistory.com/m/7
[C#, .Net] ๋ฎคํ ์ค(mutex)๋ฅผ ์ด์ฉํ ํ๋ก๊ทธ๋จ ์ค๋ณต ์คํ ๋ฐฉ์ง
์ํผ์ ์ด์ฉํด ํ๋ก๊ทธ๋จ์ ๋ง๋ค์์๋, ํ๋ก๊ทธ๋จ์ ํ๊ฐ๋ง ์คํ๋๋๋ก ํด์ผ ํ ๋๊ฐ ์์ต๋๋ค ์ด๋ฐ ๊ฒฝ์ฐ C#์ ๋ฎคํ ์ค(mutex) ํด๋์ค๋ฅผ ์ด์ฉํด ํ๋ก๊ทธ๋จ์ ์ค๋ณต ์คํ์ ๋ง์ ์ ์์ต๋๋ค ๋ฎคํ ์ค(mute
backyarddev.tistory.com