2020-03-17 09:05:52 +13:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
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();
|
2020-06-06 10:59:01 +12:00
|
|
|
|
|
|
|
|
|
using (Process p = new Process())
|
|
|
|
|
{
|
2020-06-06 18:52:37 +12:00
|
|
|
|
p.StartInfo = new ProcessStartInfo(
|
|
|
|
|
Process.GetCurrentProcess().
|
|
|
|
|
MainModule.FileName);
|
2020-06-06 10:59:01 +12:00
|
|
|
|
p.Start();
|
|
|
|
|
};
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|