-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
38 lines (36 loc) · 1.34 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
namespace BaharNarenjERP
{
static class Program
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
private static bool HasPriorInstance()
{
var currentProcess = Process.GetCurrentProcess();
var fileName = currentProcess.StartInfo.FileName;
foreach (var process in Process.GetProcessesByName(currentProcess.ProcessName).Where(process => process.Id != currentProcess.Id).Where(process => process.StartInfo.FileName == fileName))
{
SetForegroundWindow(process.MainWindowHandle);
return true;
}
return false;
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
if (HasPriorInstance()) return;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMainMdi());
}
}
}