-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
109 lines (87 loc) · 2.56 KB
/
Copy pathProgram.cs
File metadata and controls
109 lines (87 loc) · 2.56 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using SolSoft.SleepControl.Properties;
namespace SolSoft.SleepControl
{
//see: https://msdn.microsoft.com/en-us/magazine/mt620013.aspx
class Program : IDisposable
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext());
Program p = new Program(Settings.Default);
p.Start();
}
private readonly App m_app;
private readonly NotificationIconForm m_notificationIconForm;
private readonly MainWindow m_mainForm;
private readonly MainViewModel m_viewModel;
private Program(ISettings settings)
{
m_viewModel = new MainViewModel(settings);
m_app = new App();
m_app.ShutdownMode = ShutdownMode.OnExplicitShutdown;
//m_app.InitializeComponent(); //no resources, etc in the XAML so this doesn't exist
m_mainForm = new MainWindow();
m_notificationIconForm = new NotificationIconForm(); //show the notification icon
}
public void Start()
{
//form is not currently useful
//m_viewModel.ShowFormRequested += ViewModel_ShowFormRequested;
m_viewModel.ExitRequested += viewModel_ExitRequested;
m_viewModel.Initialize();
//don't quit on form closed
//m_mainForm.Closed += (sender, e) =>
//{
// m_viewModel.RequestExit();
//};
m_mainForm.DataContext = m_viewModel;
m_notificationIconForm.SetViewModel(m_viewModel);
m_app.Run();
}
private void ViewModel_ShowFormRequested(object sender, EventArgs e)
{
m_mainForm.Show();
}
void viewModel_ExitRequested(object sender, EventArgs e)
{
m_notificationIconForm.Close(); //clean up the notification icon
m_app.Shutdown();
}
#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
m_notificationIconForm.Dispose();
m_viewModel.Dispose();
}
disposedValue = true;
}
}
// This code added to correctly implement the disposable pattern.
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}