SystemTrayMenu/Utilities/AppRestart.cs

51 lines
1.2 KiB
C#
Raw Normal View History

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;
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)]
private static string GetCurrentMethod()
2020-03-17 09:05:52 +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());
}
}
}