Пример #1
0
        /// <summary>
        /// Does some work.
        /// </summary>
        /// <param name="status">The status.</param>
        private void DoSomeWork(object status)
        {
            ProgressWindowForm progressWindowForm = status as ProgressWindowForm;

            try
            {
                progressWindowForm.BeginThread(0, 1000);
                for (int i = 0; i < 1000; ++i)
                {
                    progressWindowForm.SetDisplayText(String.Format("处理第{0}条....", i));
                    progressWindowForm.StepTo(i);
                    if (progressWindowForm.IsAborting)
                    {
                        return;
                    }
                    System.Threading.Thread.Sleep(100);
                    if (progressWindowForm.IsAborting)
                    {
                        return;
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message + Environment.NewLine + exception.StackTrace);
            }
            finally
            {
                if (progressWindowForm != null)
                {
                    progressWindowForm.End();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the Click event of the buttonTest control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void buttonTest_Click(object sender, EventArgs e)
        {
            ProgressWindowForm progressWindowForm = new ProgressWindowForm();

            progressWindowForm.Text = "测试工作";
            System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(DoSomeWork), progressWindowForm);
            progressWindowForm.ShowDialog();
        }