-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormContext.cs
35 lines (30 loc) · 1009 Bytes
/
FormContext.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
using NLog;
using System.Threading;
using System.Windows.Forms;
namespace DeploymentToolkit.Blocker
{
// https://stackoverflow.com/questions/15300887/run-two-winform-windows-simultaneously
internal class FormContext : ApplicationContext
{
private static Logger _logger = LogManager.GetCurrentClassLogger();
private int openForms;
public FormContext(params Form[] forms)
{
openForms = forms.Length;
foreach (var form in forms)
{
form.FormClosed += (s, args) =>
{
//When we have closed the last of the "starting" forms,
//end the program.
if (Interlocked.Decrement(ref openForms) == 0)
{
_logger.Info("All blockers closed. Exiting application");
ExitThread();
}
};
form.Show();
}
}
}
}