{"record":{"id":"671e1ec8474916ca","repo":"peass-ng/PEASS-ng","slug":"the-current-task-is-no-longer-running","errorCode":null,"errorMessage":"The current task is no longer running.","messagePattern":"The current task is no longer running\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs","lineNumber":1014,"sourceCode":"\n        /// <summary>Gets the operational state of the running task.</summary>\n        public override TaskState State => v2RunningTask?.State ?? base.State;\n\n        /// <summary>Releases all resources used by this class.</summary>\n        public new void Dispose()\n        {\n            base.Dispose();\n            if (v2RunningTask != null) Marshal.ReleaseComObject(v2RunningTask);\n        }\n\n        /// <summary>Refreshes all of the local instance variables of the task.</summary>\n        /// <exception cref=\"InvalidOperationException\">Thrown if task is no longer running.</exception>\n        public void Refresh()\n        {\n            try { v2RunningTask?.Refresh(); }\n            catch (COMException ce) when ((uint)ce.ErrorCode == 0x8004130B)\n            {\n                throw new InvalidOperationException(\"The current task is no longer running.\", ce);\n            }\n        }\n    }\n\n    /// <summary>\n    /// Provides the methods that are used to run the task immediately, get any running instances of the task, get or set the credentials\n    /// that are used to register the task, and the properties that describe the task.\n    /// </summary>\n    [XmlType(IncludeInSchema = false)]\n    [PublicAPI]\n    public class Task : IDisposable, IComparable, IComparable<Task>, INotifyPropertyChanged\n    {\n        internal const AccessControlSections defaultAccessControlSections = AccessControlSections.Owner | AccessControlSections.Group | AccessControlSections.Access;\n        internal const SecurityInfos defaultSecurityInfosSections = SecurityInfos.Owner | SecurityInfos.Group | SecurityInfos.DiscretionaryAcl;\n        internal ITask v1Task;\n\n        private static readonly int osLibMinorVer = GetOSLibraryMinorVersion();\n        private static readonly DateTime v2InvalidDate = new DateTime(1899, 12, 30);","sourceCodeStart":996,"sourceCodeEnd":1032,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs#L996-L1032","documentation":"RunningTask.Refresh throws InvalidOperationException when the underlying v2 running-task COM object reports the task is no longer running. It means the task finished or was stopped between obtaining the RunningTask and calling Refresh, leaving the COM handle stale; the exception is documented on Refresh for exactly this lifecycle condition.","triggerScenarios":"Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/Task.cs:1014 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the task's State before calling Refresh and skip the call when it is not Running.","Catch InvalidOperationException around Refresh and treat it as task completion.","Re-acquire a fresh RunningTask via Task.Run/TaskService.GetTask instead of refreshing a stale instance.","Dispose the stale RunningTask after handling the exception to release the COM object."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}