forked from silahian/VisualHFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
80 lines (70 loc) · 2.83 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
73
74
75
76
77
78
79
80
using System;
using System.Runtime;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
namespace VisualHFT
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
//Initialize logging
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));
/*----------------------------------------------------------------------------------------------------------------------*/
/* This is to avoid errors when rendering too much in short times
*
* Exception thrown: 'System.Runtime.InteropServices.COMException' in PresentationCore.dll
* An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in PresentationCore.dll
* UCEERR_RENDERTHREADFAILURE (0x88980406)
*
*/
//RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
/*----------------------------------------------------------------------------------------------------------------------*/
//Launch the GC cleanup thread ==> *** Since using Object Pools, we improved a lot the memory prints. So We commented this out.
Task.Run(async () => { await GCCleanupAsync(); });
//Load Plugins
Task.Run(async () =>
{
try
{
await LoadPlugins();
}
catch (Exception ex)
{
// Handle the exception
Application.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("ERROR LOADING Plugins: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
});
}
});
}
protected override void OnExit(ExitEventArgs e)
{
PluginManager.PluginManager.UnloadPlugins();
base.OnExit(e);
}
private async Task LoadPlugins()
{
PluginManager.PluginManager.AllPluginsReloaded = false;
await PluginManager.PluginManager.LoadPlugins();
await PluginManager.PluginManager.StartPlugins();
PluginManager.PluginManager.AllPluginsReloaded = true;
}
private async Task GCCleanupAsync()
{
//due to the high volume of data do this periodically.(this will get fired every 5 secs)
while (true)
{
await Task.Delay(5000);
GC.Collect(0, GCCollectionMode.Forced, false); //force garbage collection
};
}
}
}