-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
96 lines (82 loc) · 3.43 KB
/
Copy pathProgram.cs
File metadata and controls
96 lines (82 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Diagnostics;
using Avalonia;
using Avalonia.Controls;
using Avalonia.ReactiveUI;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Logging;
namespace FileEncodingConvertTool;
sealed class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args)
{
try
{
Console.WriteLine("Starting application...");
Console.WriteLine($"Command line args: {string.Join(" ", args)}");
Console.WriteLine($"Current directory: {Environment.CurrentDirectory}");
var app = BuildAvaloniaApp();
Console.WriteLine("Configuring desktop lifetime...");
var lifetime = new ClassicDesktopStyleApplicationLifetime()
{
Args = args,
ShutdownMode = ShutdownMode.OnLastWindowClose
};
Console.WriteLine("Starting application setup...");
app.SetupWithLifetime(lifetime);
Console.WriteLine("Application setup completed");
if (lifetime.MainWindow == null)
{
Console.WriteLine("Error: MainWindow is null after setup");
Console.WriteLine("Available windows:");
foreach (var window in lifetime.Windows)
{
Console.WriteLine($"- {window?.Title ?? "null"}");
}
return;
}
Console.WriteLine($"MainWindow created: {lifetime.MainWindow.Title}");
Console.WriteLine("Starting application lifetime...");
lifetime.Start(args);
Console.WriteLine("Application exited normally");
}
catch (Exception ex)
{
Console.WriteLine($"Application failed to start: {ex}");
Console.WriteLine($"Exception details: {ex.ToString()}");
Console.WriteLine($"Stack trace: {ex.StackTrace}");
// 写入Windows事件日志
try
{
using (EventLog eventLog = new EventLog("Application"))
{
eventLog.Source = "FileEncodingConvertTool";
eventLog.WriteEntry($"Application failed to start: {ex}", EventLogEntryType.Error);
}
}
catch (Exception logEx)
{
Console.WriteLine($"Failed to write to event log: {logEx}");
}
throw;
}
}
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
{
Console.WriteLine("Initializing Avalonia application...");
var builder = AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace(Avalonia.Logging.LogEventLevel.Verbose)
.UseReactiveUI();
Console.WriteLine("Avalonia application initialized successfully");
Console.WriteLine($"Using Avalonia version: {typeof(AppBuilder).Assembly.GetName().Version}");
Console.WriteLine($"Using .NET runtime: {System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription}");
return builder;
}
}