2020-03-17 09:05:52 +13:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
2020-03-30 06:26:45 +13:00
|
|
|
|
using System.Windows.Forms;
|
2020-03-17 09:05:52 +13:00
|
|
|
|
|
2020-03-28 12:42:32 +13:00
|
|
|
|
namespace SystemTrayMenu.Utilities
|
2020-03-17 09:05:52 +13:00
|
|
|
|
{
|
|
|
|
|
internal class AppRestart
|
|
|
|
|
{
|
2020-04-01 07:42:49 +13:00
|
|
|
|
public static event EventHandlerEmpty BeforeRestarting;
|
2020-03-17 09:05:52 +13:00
|
|
|
|
|
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);
|
2020-03-30 06:26:45 +13:00
|
|
|
|
Application.Exit();
|
2020-03-17 09:05:52 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|