示例#1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="forkTimeout">
        /// Specifies the maximum time for <see cref="Fork(ProgramEntrypoint, string[])"/>
        /// to wait for the program to signal that it's ready by calling <see cref="ProgramReady"/>.
        /// This defaults to <b>30 seconds</b>.
        /// </param>
        public ProgramRunner(TimeSpan forkTimeout = default)
        {
            if (forkTimeout <= TimeSpan.Zero)
            {
                forkTimeout = TimeSpan.FromSeconds(30);
            }

            this.forkTimeout       = forkTimeout;
            this.programReadyEvent = new AutoResetEvent(false);
            this.programExitEvent  = new AutoResetEvent(false);

            ProgramRunner.Current = this;
        }
示例#2
0
        /// <inheritdoc/>
        public void Dispose()
        {
            TerminateFork();

            if (programReadyEvent != null)
            {
                programReadyEvent.Dispose();
                programReadyEvent = null;
            }

            if (programExitEvent != null)
            {
                programExitEvent.Dispose();
                programExitEvent = null;
            }

            Current = null;
        }