Ai
4 Star 42 Fork 6

空山明月/中书君-Rime管理器

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
App.xaml.cs 2.45 KB
一键复制 编辑 原始数据 按行查看 历史
shiqiqi 提交于 2025-02-22 11:45 +08:00 . 添加自造词按钮
using WubiMaster.ViewModels;
namespace WubiMaster;
public partial class App : Application
{
private static ViewModelLocator? locator;
private Mutex? mutex;
public static bool IsMaximized { get; set; }
public static ViewModelLocator? Locator => locator ??= App.Current.FindResource("Locator") as ViewModelLocator;
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
try
{
e.Handled = true;
LogHelper.Fatal(e.Exception.Message);
}
catch (Exception ex)
{
LogHelper.Fatal("程序发生致命错误,将终止,请联系开发人员!" + ex.Message);
this.ShowMessage("程序发生致命错误,将终止,请联系开发人员!", DialogType.Error);
Environment.Exit(0);
}
}
private void Application_Exit(object sender, ExitEventArgs e)
{
LogHelper.Info("程序退出");
}
private void Application_Startup(object sender, StartupEventArgs e)
{
if (mutex != null) return;
mutex = new Mutex(true, "WubiMaster", out bool ret);
if (!ret)
{
LogHelper.Info("禁止启用多个进程");
Environment.Exit(0);
return;
}
LogHelper.Info("程序启动");
this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
StringBuilder sbEx = new();
if (e.IsTerminating)
{
sbEx.Append("程序发生致命错误,将终止,请联系开发人员!\n");
}
if (e.ExceptionObject is Exception ex)
{
sbEx.Append(ex.Message);
}
else
{
sbEx.Append(e.ExceptionObject);
}
this.ShowMessage(sbEx.ToString(), DialogType.Error);
}
private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
{
LogHelper.Fatal(e.Exception.Message);
e.SetObserved();
this.ShowMessage(e.Exception.Message, DialogType.Error);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/hi-coder/WubiMaster.git
git@gitee.com:hi-coder/WubiMaster.git
hi-coder
WubiMaster
中书君-Rime管理器
master

搜索帮助