-
Notifications
You must be signed in to change notification settings - Fork 30
/
ApplicationLogic.cs
642 lines (586 loc) · 25.5 KB
/
ApplicationLogic.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
using System;
using System.Drawing;
using System.Net.Sockets;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAudio.Wave;
using ChromeCast.Desktop.AudioStreamer.Classes;
using ChromeCast.Desktop.AudioStreamer.Application.Interfaces;
using ChromeCast.Desktop.AudioStreamer.Streaming.Interfaces;
using ChromeCast.Desktop.AudioStreamer.Discover.Interfaces;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using ChromeCast.Desktop.AudioStreamer.Discover;
using System.Threading;
using ChromeCast.Desktop.AudioStreamer.Rest;
using System.Configuration;
using System.IO;
using System.Diagnostics;
namespace ChromeCast.Desktop.AudioStreamer.Application
{
public class ApplicationLogic : IApplicationLogic, IDisposable
{
private readonly IDevices devices;
private IMainForm mainForm;
private readonly IConfiguration configuration;
private readonly IStreamingRequestsListener streamingRequestListener;
private readonly IDiscoverDevices discoverDevices;
private readonly IDeviceStatusTimer deviceStatusTimer;
private NotifyIcon notifyIcon;
private const int trbLagMaximumValue = 1000;
private int reduceLagThreshold = trbLagMaximumValue;
private UserSettings settings = new UserSettings();
private Mp3Stream Mp3Stream = null;
private SupportedStreamFormat StreamFormatSelected = SupportedStreamFormat.Mp3_320;
private string Culture;
private readonly ILogger logger;
private Size defaultSize = new Size(850, 550);
private TasksToCancel taskList;
private bool AutoRestart { get; set; } = false;
public ApplicationLogic(IDevices devicesIn, IDiscoverDevices discoverDevicesIn
, IConfiguration configurationIn
, IStreamingRequestsListener streamingRequestListenerIn, IDeviceStatusTimer deviceStatusTimerIn
, ILogger loggerIn)
{
devices = devicesIn;
devices.SetCallback(OnAddDevice);
discoverDevices = discoverDevicesIn;
configuration = configurationIn;
streamingRequestListener = streamingRequestListenerIn;
deviceStatusTimer = deviceStatusTimerIn;
logger = loggerIn;
}
/// <summary>
/// Initialize the application.
/// </summary>
public void Initialize()
{
taskList = new TasksToCancel();
AddNotifyIcon();
LoadSettings();
configuration.Load(ApplyConfiguration, logger);
ScanForDevices();
deviceStatusTimer.StartPollingDevice(devices.OnGetStatus);
var ipAddress = Network.GetIp4Address();
if (ipAddress == null)
{
logger.Log(Properties.Strings.MessageBox_NoIPAddress);
return;
}
StartTask(() => {
streamingRequestListener.StartListening(ipAddress, OnStreamingRequestConnect, logger);
});
StartTask(() => {
new RestApi().StartListening(ipAddress, RestApiHandler.Process, logger, devices, mainForm);
});
}
/// <summary>
/// Callback for the StreamingRequestListener, a device has made a new streaming connection.
/// </summary>
/// <param name="socketIn">the connected socket</param>
/// <param name="httpRequestIn">the HTTP headers, including the 'CAST-DEVICE-CAPABILITIES' header</param>
public void OnStreamingRequestConnect(Socket socketIn, string httpRequestIn)
{
if (devices == null)
return;
logger.Log(string.Format("Connection added from {0}", socketIn.RemoteEndPoint));
devices.AddStreamingConnection(socketIn, httpRequestIn, StreamFormatSelected);
}
/// <summary>
/// Callback for the loopback recorder, new audio data is captured.
/// </summary>
/// <param name="dataToSendIn">the audio data in wav format</param>
/// <param name="formatIn">the wav format that's used</param>
public void OnRecordingDataAvailable(byte[] dataToSendIn, WaveFormat formatIn)
{
if (devices == null)
return;
if (!StreamFormatSelected.Equals(SupportedStreamFormat.Wav) &&
!StreamFormatSelected.Equals(SupportedStreamFormat.Wav_16bit) &&
!StreamFormatSelected.Equals(SupportedStreamFormat.Wav_24bit) &&
!StreamFormatSelected.Equals(SupportedStreamFormat.Wav_32bit))
{
if (Mp3Stream == null)
{
Mp3Stream = new Mp3Stream(formatIn, StreamFormatSelected, logger);
}
Mp3Stream.Encode(dataToSendIn.ToArray());
dataToSendIn = Mp3Stream.Read();
}
if (dataToSendIn.Length > 0)
{
devices.OnRecordingDataAvailable(dataToSendIn, formatIn, reduceLagThreshold, StreamFormatSelected);
}
}
/// <summary>
/// Clear the audio data in the mp3 encoder.
/// </summary>
public void ClearMp3Buffer()
{
Mp3Stream = null;
}
/// <summary>
/// Callback for Devices, a new device is added.
/// </summary>
/// <param name="deviceIn">the new device</param>
public void OnAddDevice(IDevice deviceIn)
{
if (deviceIn == null || mainForm == null)
return;
try
{
var menuItem = new MenuItem
{
Text = deviceIn.GetFriendlyName()
};
menuItem.Click += deviceIn.OnClickPlayPause;
notifyIcon?.ContextMenu?.MenuItems?.Add(notifyIcon.ContextMenu.MenuItems.Count - 1, menuItem);
deviceIn.SetMenuItem(menuItem);
deviceIn.OnGetStatus();
}
catch (Exception ex)
{
logger.Log(ex, "ApplicationLogic.OnAddDevice");
}
mainForm.AddDevice(deviceIn);
}
/// <summary>
/// Set the dependencies.
/// </summary>
/// <param name="mainFormIn">the form</param>
public void SetDependencies(MainForm mainFormIn)
{
mainForm = mainFormIn;
}
/// <summary>
/// The user changed the checkbox to automatically restart devices when closed.
/// </summary>
public void OnSetAutoRestart(bool autoRestartIn)
{
AutoRestart = autoRestartIn;
}
/// <summary>
/// Automaticaly restart devices y/n.
/// </summary>
public bool GetAutoRestart()
{
return AutoRestart;
}
/// <summary>
/// The user changed the ip address in the user interface.
/// Restart streaming using the new ip address.
/// </summary>
/// <param name="ipAddressIn">the selected ip address</param>
public void ChangeIPAddressUsed(IPAddress ipAddressIn)
{
if (devices == null || streamingRequestListener == null)
return;
logger.Log($"Change IP4 address: {ipAddressIn}");
devices.Stop();
streamingRequestListener.StopListening();
ScanForDevices();
StartTask(() => {
streamingRequestListener.StartListening(ipAddressIn, OnStreamingRequestConnect, logger);
});
var cancellationTokenSource = new CancellationTokenSource();
StartTask(() =>
{
Task.Delay(2500).Wait();
if (cancellationTokenSource.IsCancellationRequested)
return;
devices.Start();
}, cancellationTokenSource);
}
/// <summary>
/// The user changed the stream format in the user interface.
/// Restart streaming in the new format.
/// </summary>
/// <param name="formatIn">the chosen format</param>
public void SetStreamFormat(SupportedStreamFormat formatIn)
{
if (devices == null)
return;
if (formatIn != StreamFormatSelected)
{
logger.Log($"Set stream format to {formatIn}");
StreamFormatSelected = formatIn;
Mp3Stream = null;
devices.Stop();
devices.Start();
}
}
/// <summary>
/// The user changed the language in the user interface.
/// </summary>
/// <param name="cultureIn">the chosen culture</param>
public void SetCulture(string cultureIn)
{
Culture = cultureIn;
}
/// <summary>
/// Search for new devices in the network.
/// </summary>
public void ScanForDevices()
{
if (devices == null || discoverDevices == null)
return;
discoverDevices.Discover(devices.OnDeviceAvailable);
}
/// <summary>
/// Load and apply the settings.
/// </summary>
private void LoadSettings()
{
if (settings == null || devices == null || mainForm == null)
return;
try
{
if (!settings.Upgraded ?? true)
{
settings.Upgrade();
settings.Upgraded = true;
}
devices.SetSettings(settings);
mainForm.SetAutoStart(settings.AutoStartDevices ?? false);
mainForm.SetAutoRestart(settings.AutoRestart ?? false);
mainForm.SetStartLastUsedDevices(settings.StartLastUsedDevices ?? false);
mainForm.SetWindowVisibility(settings.ShowWindowOnStart ?? true);
mainForm.SetKeyboardHooks(settings.UseKeyboardShortCuts ?? false);
mainForm.SetIP4AddressUsed(settings.Ip4AddressUsed ?? string.Empty);
mainForm.SetStreamFormat(settings.StreamFormat ?? SupportedStreamFormat.Mp3_320);
mainForm.SetCulture(settings.Culture ?? CultureInfo.CurrentUICulture.TwoLetterISOLanguageName);
mainForm.SetLogDeviceCommunication(settings.LogDeviceCommunication ?? false);
mainForm.SetLagValue(settings.LagControlValue ?? 1000);
mainForm.SetStartApplicationWhenWindowsStarts(settings.StartApplicationWhenWindowsStarts ?? false);
mainForm.SetFilterDevices(settings.FilterDevices ?? FilterDevicesEnum.ShowAll);
if (settings.Size == null || settings.Size.Value.Width < 50 || settings.Size.Value.Height < 50)
settings.Size = defaultSize;
mainForm.SetSize(settings.Size.Value);
mainForm.SetPosition(
Math.Min(Math.Max(settings.Left.Value, 0), Screen.PrimaryScreen.Bounds.Width),
Math.Min(Math.Max(settings.Top.Value, 0), Screen.PrimaryScreen.Bounds.Height)
);
mainForm.SetExtraBufferInSeconds(settings.ExtraBufferInSeconds ?? 4);
mainForm.SetRecordingDeviceID(settings.RecordingDeviceID ?? null);
mainForm.SetAutoMute(settings.AutoMute ?? false);
mainForm.SetMinimizeToTray(settings.MinimizeToTray ?? false);
mainForm.SetConvertMultiChannelToStereo(settings.ConvertMultiChannelToStereo ?? false);
mainForm.SetDarkMode(settings.DarkMode ?? false);
if (settings.ChromecastDiscoveredDevices != null)
{
settings.ChromecastDiscoveredDevices = RemoveOldEntries(settings.ChromecastDiscoveredDevices);
for (int i = 0; i < settings.ChromecastDiscoveredDevices.Count; i++)
{
StartTask(DeviceInformation.CheckDeviceIsOn(settings.ChromecastDiscoveredDevices[i], devices.OnDeviceAvailable, logger));
}
}
}
catch (ConfigurationErrorsException ex)
{
// Corrupted config file, remove the config file.
File.Delete(((ConfigurationErrorsException)ex.InnerException).Filename);
Process.GetCurrentProcess().Kill();
}
}
/// <summary>
/// Save the settings.
/// </summary>
public void SaveSettings()
{
if (settings == null || devices == null || mainForm == null)
return;
var discoveredDevices = settings.ChromecastDiscoveredDevices;
if (discoveredDevices == null)
discoveredDevices = new List<DiscoveredDevice>();
// Remove (old) entries of devices without a saved MAC address,
// and remove (old) entries of groups without a saved ID.
discoveredDevices = RemoveOldEntries(discoveredDevices);
foreach (var host in devices.GetHosts())
{
if (host.IsGroup)
{
var discoveredDevice = discoveredDevices.Where(x => x.Id == host.Id);
if (!discoveredDevice.Any())
{
discoveredDevices.Add(host);
}
else
{
if (host.DeviceState == Communication.DeviceState.ConnectError)
{
discoveredDevices.Remove(discoveredDevice.First());
}
else
{
discoveredDevice.First().Name = host.Name;
discoveredDevice.First().IPAddress = host.IPAddress;
discoveredDevice.First().Port = host.Port;
discoveredDevice.First().DeviceState = host.DeviceState;
}
}
}
else
{
var discoveredDevice = discoveredDevices.Where(x => x.MACAddress == host.MACAddress);
if (!discoveredDevice.Any())
{
discoveredDevices.Add(host);
}
else
{
discoveredDevice.First().DeviceState = host.DeviceState;
}
}
}
settings.ChromecastDiscoveredDevices = discoveredDevices;
settings.UseKeyboardShortCuts = mainForm.GetUseKeyboardShortCuts();
settings.AutoStartDevices = mainForm.GetAutoStartDevices();
settings.AutoRestart = mainForm.GetAutoRestart();
settings.StartLastUsedDevices = mainForm.GetStartLastUsedDevices();
settings.ShowWindowOnStart = mainForm.GetShowWindowOnStart();
settings.Ip4AddressUsed = mainForm.GetIP4AddressUsed();
settings.StreamFormat = StreamFormatSelected;
settings.Culture = Culture;
settings.LogDeviceCommunication = mainForm.GetLogDeviceCommunication();
settings.ShowLagControl = mainForm.GetShowLagControl();
settings.LagControlValue = mainForm.GetLagValue();
settings.StartApplicationWhenWindowsStarts = mainForm.GetStartApplicationWhenWindowsStarts();
settings.FilterDevices = mainForm.GetFilterDevices();
settings.Size = mainForm.GetSize();
settings.Left = mainForm.GetLeft();
settings.Top = mainForm.GetTop();
settings.ExtraBufferInSeconds = mainForm.GetExtraBufferInSeconds();
settings.RecordingDeviceID = mainForm.GetRecordingDeviceID();
settings.AutoMute = mainForm.GetAutoMute();
settings.MinimizeToTray = mainForm.GetMinimizeToTray();
settings.ConvertMultiChannelToStereo = mainForm.GetConvertMultiChannelToStereo();
settings.DarkMode = mainForm.GetDarkMode();
settings.Save();
}
/// <summary>
/// Remove (old) entries of devices without a saved MAC address,
/// and remove (old) entries of groups without a saved ID.
/// </summary>
private static List<DiscoveredDevice> RemoveOldEntries(List<DiscoveredDevice> discoveredDevices)
{
return discoveredDevices.Where(
x => (x.IsGroup && !string.IsNullOrEmpty(x.Id)) || (!x.IsGroup && !string.IsNullOrEmpty(x.MACAddress))).ToList();
}
/// <summary>
/// Reset to the deafult setting.
/// </summary>
public void ResetSettings()
{
if (devices == null || mainForm == null)
return;
if (settings == null)
settings = new UserSettings();
settings.ChromecastDiscoveredDevices = new List<DiscoveredDevice>();
settings.UseKeyboardShortCuts = false;
settings.AutoStartDevices = false;
settings.StartLastUsedDevices = false;
settings.ShowWindowOnStart = true;
settings.AutoRestart = false;
settings.Ip4AddressUsed = string.Empty;
settings.StreamFormat = SupportedStreamFormat.Mp3_320;
settings.Culture = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
settings.LogDeviceCommunication = false;
settings.ShowLagControl = false;
settings.LagControlValue = 1000;
settings.StartApplicationWhenWindowsStarts = false;
settings.FilterDevices = FilterDevicesEnum.ShowAll;
settings.Size = defaultSize;
settings.Left = Screen.PrimaryScreen.Bounds.Width / 2 - settings.Size.Value.Width / 2;
settings.Top = Screen.PrimaryScreen.Bounds.Height / 2 - settings.Size.Value.Height / 2;
settings.ExtraBufferInSeconds = 4;
settings.RecordingDeviceID = null;
settings.AutoMute = false;
settings.MinimizeToTray = false;
settings.ConvertMultiChannelToStereo = false;
devices.SetSettings(settings);
mainForm.SetAutoStart(settings.AutoStartDevices.Value);
mainForm.SetStartLastUsedDevices(settings.StartLastUsedDevices.Value);
mainForm.SetAutoRestart(settings.AutoRestart.Value);
mainForm.SetWindowVisibility(settings.ShowWindowOnStart.Value);
mainForm.SetKeyboardHooks(settings.UseKeyboardShortCuts.Value);
mainForm.SetIP4AddressUsed(settings.Ip4AddressUsed);
mainForm.SetStreamFormat(settings.StreamFormat.Value);
mainForm.SetCulture(settings.Culture);
mainForm.SetLogDeviceCommunication(settings.LogDeviceCommunication.Value);
mainForm.SetLagValue(settings.LagControlValue.Value);
mainForm.SetStartApplicationWhenWindowsStarts(settings.StartApplicationWhenWindowsStarts.Value);
mainForm.SetFilterDevices(settings.FilterDevices.Value);
mainForm.SetSize(settings.Size.Value);
mainForm.SetExtraBufferInSeconds(settings.ExtraBufferInSeconds.Value);
mainForm.SetRecordingDeviceID(settings.RecordingDeviceID);
mainForm.SetAutoMute(settings.AutoMute.Value);
mainForm.SetMinimizeToTray(settings.MinimizeToTray.Value);
mainForm.SetConvertMultiChannelToStereo(settings.ConvertMultiChannelToStereo.Value);
mainForm.SetDarkMode(settings.DarkMode.Value);
settings.Save();
devices?.Dispose();
if (notifyIcon?.ContextMenu != null)
{
for (int i = notifyIcon.ContextMenu.MenuItems.Count - 2; i >= 0; i--)
{
notifyIcon.ContextMenu.MenuItems[i].Dispose();
}
}
ScanForDevices();
}
/// <summary>
/// Get the streaming url.
/// </summary>
/// <returns>the url that can be used to open a stream</returns>
public string GetStreamingUrl()
{
if (mainForm == null || streamingRequestListener == null)
return null;
mainForm.GetStreamFormat();
return streamingRequestListener.GetStreamimgUrl();
}
/// <summary>
/// Close the application.
/// </summary>
public void CloseApplication()
{
SaveSettings();
Dispose(true);
}
public void SetLagThreshold(int lagThresholdIn)
{
reduceLagThreshold = lagThresholdIn;
}
/// <summary>
/// Dispose.
/// </summary>
public void Dispose()
{
Dispose(true);
}
/// <summary>
/// Dispose.
/// </summary>
protected virtual void Dispose(bool disposing)
{
devices?.Dispose();
streamingRequestListener?.StopListening();
streamingRequestListener?.Dispose();
Mp3Stream?.Dispose();
NativeMethods.StopSetWindowsHooks();
if (notifyIcon != null) notifyIcon.Visible = false;
notifyIcon?.Dispose();
mainForm?.Dispose();
taskList?.Dispose();
}
/// <summary>
/// The devices filter has changed.
/// </summary>
/// <param name="value">new filter value</param>
public void SetFilterDevices(FilterDevicesEnum value)
{
if (devices == null)
return;
devices.SetFilterDevices(value);
}
/// <summary>
/// Was the device playing when the application was closed for the last time?
/// </summary>
/// <returns>true if the device was playing, or false</returns>
public bool WasPlaying(DiscoveredDevice discoveredDevice)
{
if (settings.ChromecastDiscoveredDevices == null)
return false;
for (int i = 0; i < settings.ChromecastDiscoveredDevices.Count; i++)
{
if (settings.ChromecastDiscoveredDevices[i].Port == discoveredDevice.Port &&
settings.ChromecastDiscoveredDevices[i].Name == discoveredDevice.Name)
{
return settings.ChromecastDiscoveredDevices[i].DeviceState == Communication.DeviceState.Playing ||
settings.ChromecastDiscoveredDevices[i].DeviceState == Communication.DeviceState.Buffering ||
settings.ChromecastDiscoveredDevices[i].DeviceState == Communication.DeviceState.LoadingMedia;
}
}
return false;
}
#region private helpers
/// <summary>
/// Add an icon to the systray, with a context menu for the devices.
/// </summary>
private void AddNotifyIcon()
{
try
{
var contextMenu = new ContextMenu();
var menuItem = new MenuItem
{
Index = 0,
Text = Properties.Strings.TrayIcon_Close
};
menuItem.Click += new EventHandler(CloseApplication);
contextMenu.MenuItems.AddRange(new MenuItem[] { menuItem });
notifyIcon = new NotifyIcon();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
notifyIcon.Icon = (Icon)resources.GetObject("$this.Icon");
notifyIcon.Visible = true;
notifyIcon.Text = Properties.Strings.MainForm_Text;
notifyIcon.ContextMenu = contextMenu;
notifyIcon.Click += mainForm.ToggleFormVisibility;
}
catch (Exception ex)
{
logger.Log(ex, "ApplicationLogic.AddNotifyIcon");
}
}
/// <summary>
/// Apply the settings in the configuration file.
/// </summary>
/// <param name="ipAddressesDevicesIn">
/// ip addresses & device names
/// format: 192.168.0.1,DeviceName1;192.168.0.2,DeviceName2
/// </param>
private void ApplyConfiguration(string ipAddressesDevicesIn, bool showLagControl)
{
try
{
mainForm.ShowLagControl(showLagControl);
if (!string.IsNullOrWhiteSpace(ipAddressesDevicesIn))
{
var ipDevices = ipAddressesDevicesIn.Split(';');
foreach (var ipDevice in ipDevices)
{
var arrDevice = ipDevice.Split(',');
devices.OnDeviceAvailable(
new DiscoveredDevice
{
IPAddress = arrDevice[0],
Name = arrDevice[1],
Port = 8009 // Port = 8009, adding device groups via the config is not possible.
});
}
}
}
catch (Exception ex)
{
logger.Log(ex, "ApplicationLogic.ApplyConfiguration");
}
}
/// <summary>
/// Callback for the systray icon to close the application.
/// </summary>
private void CloseApplication(object sender, EventArgs e)
{
CloseApplication();
}
/// <summary>
/// Start an action in a new task.
/// </summary>
public void StartTask(Action action, CancellationTokenSource cancellationTokenSource = null)
{
taskList.Add(action, cancellationTokenSource);
}
#endregion
}
}