A:增减错误处理

D:调整公共项目
This commit is contained in:
jimmy committed 2025-05-27 23:05:20 +08:00
1 parent 67889796ed
commit 2831deffe3
12 files changed
+120 -109

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# Rider 忽略的文件
/modules.xml
/.idea.UI.Shared.iml
/contentModel.xml
/projectSettingsUpdater.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
+1 -3
View File
@@ -1,8 +1,6 @@
<Application x:Class="UI.Shared.Wpf.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:UI.Shared.Wpf"
StartupUri="MainWindow.xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
</Application.Resources>
+3 -7
View File
@@ -1,12 +1,8 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace UI.Shared.Wpf;
namespace UI.Shared.Wpf;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
public partial class App : System.Windows.Application
{
}
}
+38
View File
@@ -0,0 +1,38 @@
using System.Windows;
namespace UI.Shared.Wpf;
public static class GlobalExceptionHandler
{
public static void RegisterGlobalExceptionHandlers(System.Windows.Application app)
{
// UI线程异常处理
app.DispatcherUnhandledException += (sender, e) =>
{
HandleException(e.Exception, "UI线程异常");
e.Handled = true;
};
// 非UI线程异常处理
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
{
if (e.ExceptionObject is Exception ex)
HandleException(ex, "非UI线程异常");
};
// 任务未观察到的异常处理
TaskScheduler.UnobservedTaskException += (sender, e) =>
{
HandleException(e.Exception, "任务未观察异常");
e.SetObserved();
};
}
private static void HandleException(Exception ex, string context)
{
// TODO: 替换为你自己的日志系统或上报服务
string message = $"【{context}】{ex.Message}\n{ex.StackTrace}";
MessageBox.Show(message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
// 例如 LogHelper.LogError(ex);
}
}
-12
View File
@@ -1,12 +0,0 @@
<Window x:Class="UI.Shared.Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:UI.Shared.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
</Grid>
</Window>
-23
View File
@@ -1,23 +0,0 @@
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace UI.Shared.Wpf;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
+12
View File
@@ -8,4 +8,16 @@
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</ApplicationDefinition>
</ItemGroup>
</Project>