-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.xaml.cs
72 lines (65 loc) · 1.85 KB
/
App.xaml.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using MegatecUpsController.Properties;
using Microsoft.VisualBasic.ApplicationServices;
using System;
using System.Windows;
namespace MegatecUpsController
{
/// <summary>
/// Логика взаимодействия для App.xaml
/// </summary>
public partial class App : Application
{
App()
{
InitializeComponent();
}
[STAThread]
static void Main()
{
SingleInstanceManager manager = new SingleInstanceManager();
manager.Run(new[] { "megatecupscontroller" });
}
}
public class SingleInstanceManager : WindowsFormsApplicationBase
{
SingleInstanceApplication app;
public SingleInstanceManager()
{
this.IsSingleInstance = true;
}
protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
{
app = new SingleInstanceApplication();
app.Run();
return false;
}
protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs)
{
base.OnStartupNextInstance(eventArgs);
app.Activate();
}
}
public class SingleInstanceApplication : Application
{
protected override void OnStartup(System.Windows.StartupEventArgs e)
{
base.OnStartup(e);
MainWindow window = new MainWindow();
if (Settings.Default.runMinimized)
{
window.WindowState = WindowState.Minimized;
window.Show();
window.Hide();
}
else
{
window.Show();
}
}
public void Activate()
{
MainWindow.WindowState = WindowState.Normal;
MainWindow.Activate();
}
}
}