Microsoft.Azure.WebJobs.Script.ScriptHostManager.Orphan C# (CSharp) Method

Orphan() private method

Remove the ScriptHost instance from the live instances collection, allowing it to finish currently executing functions before stopping and disposing of it.
private Orphan ( ScriptHost instance, bool forceStop = false ) : Task
instance ScriptHost The instance to remove
forceStop bool Forces the call to stop and dispose of the instance, even if it isn't present in the live instances collection.
return Task
        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();
            }
        }