コード例 #1
0
        internal static void StopJobsOnExit()
        {
            bool force = false;

            while (JobList.Count > 0)
            {
                // try to get a job because the list may get empty after the check for the Count
                Job job;
                try
                {
                    job = JobList[0];
                }
                catch (ArgumentOutOfRangeException)
                {
                    return;
                }

                if (force || !job.IsRunning && job.Length == 0)
                {
                    if (job.IsRunning)
                    {
                        job.StopJob();
                    }
                    job.Dispose();
                    continue;
                }

                string message = string.Format(null, @"
Job:
{0}

State: {1}
Output: {2}

Abort: discard the job
Retry: wait for exit or view output
Ignore: discard all jobs and output

", job.ToLine(100), job.StateText, job.Length);

                Far.Api.UI.WindowTitle = Res.BackgroundJobs;
                switch (Far.Api.Message(message, Res.BackgroundJobs, MessageOptions.Gui | MessageOptions.AbortRetryIgnore))
                {
                case 0:
                    if (job.IsRunning)
                    {
                        job.StopJob();
                    }
                    job.Dispose();
                    break;

                case 1:
                    if (job.IsRunning)
                    {
                        Far.Api.UI.WindowTitle = "Waiting for a background job...";
                        job.Finished.WaitOne();
                    }
                    else
                    {
                        if (job.JobUI.Length > 0)
                        {
                            Zoo.StartExternalViewer(job.FileName).WaitForExit();
                        }

                        job.Dispose();
                    }
                    break;

                default:
                    force = true;
                    continue;
                }
            }
        }