예제 #1
0
 public static void TryForceExit(this IProcess process)
 {
     if (process != null)
     {
         process.ForceExit();
     }
 }
예제 #2
0
    static void Run_Internal <I, O>(this IProcess <I> process, I input, ProcessExitCallback <O> callback, IProcess parent)
    {
        if (process is ISettableParent)
        {
            ((ISettableParent)process).SetParent(parent);
        }

        ProcessExitCallback castCallback = null;

        if (parent != null)
        {
            ProcessExitCallback forceChildExit = (s, e) => {
                process.OnExit -= castCallback;
                process.ForceExit();
            };
            ProcessExitCallback detachChild = (s, e) => parent.OnExit -= forceChildExit;
            process.OnExit += detachChild;
            process.OnExit += (s, e) => RemoveAllEvents(process);
            parent.OnExit  += forceChildExit;
        }

        if (callback != null)
        {
            castCallback    = (s, e) => callback(s, (O)e);
            process.OnExit += castCallback;
        }

        if (process is IDebugMethods)
        {
            var methods = ((IDebugMethods)process).GetMethods().ToArray();
            DebugMenuListener.AddContextMethods(methods);
            process.OnExit += (s, e) => DebugMenuListener.RemoveContextMethods(methods);
        }

        process.Initialize(input);
    }