namespace Jugenddienst_Stunden; /// /// Die Hauptanwendungsklasse. /// public partial class App : Application { /// /// Initialisiert eine neue Instanz der -Klasse. /// public App() { InitializeComponent(); //UnhandledException: Wird gefangen, wenn eine Ausnahme in einem beliebigen nicht verwalteten Thread außerhalb des individuellen Kontexts auftritt. AppDomain.CurrentDomain.UnhandledException += (sender, e) => { if (e.ExceptionObject is Exception ex) { HandleException(ex); } }; //UnobservedTaskException: Wird ausgelöst, wenn eine Ausnahme in einem asynchronen Task auftritt und nicht behandelt wird. TaskScheduler.UnobservedTaskException += (sender, e) => { HandleException(e.Exception); e.SetObserved(); }; //Dispatcher: Hilft bei der Handhabung von UI-bezogenen Ausnahmen innerhalb des UI-Threads. if (Current?.Dispatcher != null) { Current.Dispatcher.Dispatch(async () => { try { // Anwendungscode hier await Task.CompletedTask; // Dummy await to avoid CS1998 } catch (Exception ex) { HandleException(ex); } }); } MainPage = new AppShell(); } private void HandleException(Exception ex) { // Fehlerbehandlungscode Console.WriteLine($"Globale Ausnahme: {ex?.Message}"); // Optional: Logging oder Benutzerbenachrichtigung } //protected override Window CreateWindow(IActivationState activationState) => //new Window(new AppShell()) { // Width = 500, // Height = 900 //}; // protected override Window CreateWindow(IActivationState activationState) { // Window window = base.CreateWindow(activationState); // window.Activated += Window_Activated; // return window; // } // private async void Window_Activated(object sender, EventArgs e) { //#if WINDOWS // const int DefaultWidth = 500; // const int DefaultHeight = 900; // var window = sender as Window; // // change window size. // window.Width = DefaultWidth; // window.Height = DefaultHeight; // // give it some time to complete window resizing task. // await window.Dispatcher.DispatchAsync(() => { }); // var disp = DeviceDisplay.Current.MainDisplayInfo; // // move to screen center // //window.X = (disp.Width / disp.Density - window.Width) / 2; // //window.Y = (disp.Height / disp.Density - window.Height) / 2; //#endif // } }