/* * ThreadPilot - Advanced Windows Process and Power Plan Manager * Copyright (C) 2025 Prime Build * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, version 3 only. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ namespace ThreadPilot.Services { using System; using System.Threading.Tasks; internal static class TaskSafety { public static void FireAndForget(Task task, Action onError) { _ = ObserveAsync(task, onError); } private static async Task ObserveAsync(Task task, Action onError) { try { await task.ConfigureAwait(false); } catch (OperationCanceledException) { // Cancellation is expected in shutdown paths. } catch (Exception ex) { onError(ex); } } } }