2020-03-17 09:05:52 +13:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
|
|
namespace SystemTrayMenu.Helper
|
|
|
|
|
{
|
|
|
|
|
internal class AppRestart
|
|
|
|
|
{
|
|
|
|
|
public static event EventHandler BeforeRestarting;
|
|
|
|
|
|
2020-03-24 00:32:47 +13:00
|
|
|
|
private static void Restart(string reason)
|
2020-03-17 09:05:52 +13:00
|
|
|
|
{
|
|
|
|
|
BeforeRestarting?.Invoke();
|
|
|
|
|
Log.Info($"Restart by '{reason}'");
|
|
|
|
|
Log.Close();
|
|
|
|
|
Process.Start(Assembly.GetExecutingAssembly().
|
|
|
|
|
ManifestModule.FullyQualifiedName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
2020-03-24 00:32:47 +13:00
|
|
|
|
private static string GetCurrentMethod()
|
2020-03-17 09:05:52 +13:00
|
|
|
|
{
|
2020-03-24 00:38:23 +13:00
|
|
|
|
StackTrace st = new StackTrace();
|
|
|
|
|
StackFrame sf = st.GetFrame(1);
|
2020-03-17 09:05:52 +13:00
|
|
|
|
|
|
|
|
|
return sf.GetMethod().Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static void ByThreadException()
|
|
|
|
|
{
|
|
|
|
|
Restart(GetCurrentMethod());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static void ByMenuNotifyIcon()
|
|
|
|
|
{
|
|
|
|
|
Restart(GetCurrentMethod());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static void ByDisplaySettings(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Restart(GetCurrentMethod());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static void ByConfigChange()
|
|
|
|
|
{
|
|
|
|
|
Restart(GetCurrentMethod());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|