/// <summary> /// This method adds and runs a FAF task with a custom external ID /// </summary> /// <param name="taskId"></param> /// <param name="task"></param> /// <returns></returns> protected string FireAndForget(string taskId, DelegateFireAndForgetTask task) { // Define our ticker Core.Ticker ticker = new Core.Ticker(); // Start the ticker ticker.Reset(); // Add the FAF task to the instance _fafMap[taskId] = task .Invoke(taskId, ticker) .ContinueWith((asyncTask) => { // Stop our ticker and localize the time table Core.TickerTimeTable tickerTimeTable = ticker.Halt(); // Define our parts List <string> parts = new List <string>(); // Define our prefix parts.Add($"[Internal: {asyncTask.Id} F*x: {taskId}] Task"); // Check the cancelled flag if (asyncTask.IsCanceled) { parts.Add("was Cancelled in ${taskElapsed}"); } // Check the completed successfully flag if (asyncTask.IsCompletedSuccessfully) { parts.Add("Completed Successfully in ${taskElapsed}"); } // Check the faulted flag if (asyncTask.IsFaulted) { parts.Add("Faulted in ${taskElapsed} [Error: ${exceptionMessage}]"); } // Check the completed flag if (asyncTask.IsCompleted) { parts.Add("Completed in ${taskElapsed}"); } // Log the message LogMessage( Helper.Message.New(string.Join(' ', parts)) .WithDataObject("taskElapsed", tickerTimeTable.Elapsed) .WithDataObject("exceptionMessage", asyncTask.Exception?.Message)); // Dispose of the task asyncTask.Dispose(); }); // Return the unique ID of the FAF task return(taskId); }
/// <summary> /// This method adds and runs FAF task with an external ID /// </summary> /// <param name="taskId"></param> /// <param name="task"></param> /// <returns></returns> protected Guid FireAndForget(Guid taskId, DelegateFireAndForgetTask <Guid> task) => FireAndForget <Guid>(taskId, task);
/// <summary> /// This method adds and runs a completely anonymous FAF task /// </summary> /// <param name="task"></param> /// <returns></returns> protected Guid FireAndForget(DelegateFireAndForgetTask <Guid> task) => FireAndForget <Guid>(Guid.NewGuid(), task);