/// <summary> /// Remove the <see cref="ScriptHost"/> instance from the live instances collection, /// allowing it to finish currently executing functions before stopping and disposing of it. /// </summary> /// <param name="instance">The <see cref="ScriptHost"/> instance to remove</param> /// <param name="forceStop">Forces the call to stop and dispose of the instance, even if it isn't present in the live instances collection.</param> private async Task Orphan(ScriptHost instance, bool forceStop = false) { lock (_liveInstances) { bool removed = _liveInstances.Remove(instance); if (!forceStop && !removed) { return; // somebody else is handling it } } try { // this thread now owns the instance if (instance.TraceWriter != null) { instance.TraceWriter.Info("Stopping Host"); } await instance.StopAsync(); } finally { instance.Dispose(); } }
/// <summary> /// Remove the <see cref="ScriptHost"/> instance from the live instances collection, /// allowing it to finish currently executing functions before stopping and disposing of it. /// </summary> /// <param name="instance">The <see cref="ScriptHost"/> instance to remove</param> /// <param name="forceStop">Forces the call to stop and dispose of the instance, even if it isn't present in the live instances collection.</param> private async Task Orphan(ScriptHost instance, bool forceStop = false) { lock (_liveInstances) { bool removed = _liveInstances.Remove(instance); if (!forceStop && !removed) { return; // somebody else is handling it } } try { // this thread now owns the instance string message = "Stopping Host"; instance.TraceWriter?.Info(message); instance.Logger?.LogInformation(message); await instance.StopAsync(); } finally { instance.Dispose(); } }
private static async Task StopAndDisposeAsync(ScriptHost instance) { try { await instance.StopAsync(); } catch { // best effort } finally { instance.Dispose(); } }
// Let the existing host instance finish currently executing functions. private async Task Orphan(ScriptHost instance) { lock (_liveInstances) { bool removed = _liveInstances.Remove(instance); if (!removed) { return; // somebody else is handling it } } // this thread now owns the instance await instance.StopAsync(); instance.Dispose(); }
/// <summary> /// Remove the <see cref="ScriptHost"/> instance from the live instances collection, /// allowing it to finish currently executing functions before stopping and disposing of it. /// </summary> /// <param name="instance">The <see cref="ScriptHost"/> instance to remove</param> /// <param name="forceStop">Forces the call to stop and dispose of the instance, even if it isn't present in the live instances collection.</param> /// <returns></returns> private async Task Orphan(ScriptHost instance, bool forceStop = false) { lock (_liveInstances) { bool removed = _liveInstances.Remove(instance); if (!forceStop && !removed) { return; // somebody else is handling it } } try { // this thread now owns the instance if (instance.TraceWriter != null) { instance.TraceWriter.Info("Stopping Host"); } await instance.StopAsync(); } finally { instance.Dispose(); } }