⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threadcontrolpanel.cs

📁 用C#编写的一个款搜索engine的源代码!摘自<Visual c#2005 程序设计>
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using SECompare.Structure;
using SECompare.Controls;

namespace SECompare.Controls
{
    public partial class ThreadControlPanel : UserControl
    {
        public ThreadControlPanel()
        {
            InitializeComponent();

            this.m_ControlsToDisable = new ArrayList(2);
        }

        private ArrayList m_ControlsToDisable;   //The controls to be disabled while the thread is running.

        /// <summary>
        /// Set the EngineCheckBox object as the selector of engines.
        /// </summary>
        public EngineCheckBox EngineCheckBox
        {
            set
            {
                this.m_EngineCheckBox = value;
            }
        }
        private EngineCheckBox m_EngineCheckBox;      //The source to read checked status of engines 

        /// <summary>
        /// Set the thread to run and controlled by the panel.
        /// </summary>
        public ThreadStatus ThreadStatus
        {
            set
            {
                this.m_ThreadStatus = value;
            }
        }
        private ThreadStatus m_ThreadStatus;        //Thread controller

        /// <summary>
        /// Set title which is displayed on the top of the control.
        /// </summary>
        public String Title
        {
            set
            {
                this.lblTitle.Text = value;
            }
        }

        public void AddControlToDisable(System.Windows.Forms.Control control)
        {
            this.m_ControlsToDisable.Add(control);
        }

        private void SetControlsEnable(bool Enable)
        {
            foreach (System.Windows.Forms.Control control in this.m_ControlsToDisable)
                control.Enabled = Enable;
        }

        private void btnRun_Click(object sender, System.EventArgs e)
        {
            if (this.m_ThreadStatus == null)
            {
                MessageBox.Show("Thread is not initialized!", "Error");
                return;
            }
            //Run thread
            this.m_ThreadStatus.EngineSetting = this.m_EngineCheckBox.Checked;
            this.m_ThreadStatus.Start();
            //Set controls status
            this.SetControlsEnable(false);
            this.m_EngineCheckBox.Enabled = false;
            this.btnRun.Enabled = false;
            this.btnPause.Enabled = true;
            this.btnResume.Enabled = false;
            this.btnStop.Enabled = true;
            this.timer.Start();
        }

        private void btnPause_Click(object sender, System.EventArgs e)
        {
            //Pause thread
            this.m_ThreadStatus.Suspend();
            //Set controls Status
            this.btnRun.Enabled = false;
            this.btnPause.Enabled = false;
            this.btnResume.Enabled = true;
            this.btnStop.Enabled = true;
            this.timer.Stop();
        }

        private void btnResume_Click(object sender, System.EventArgs e)
        {
            //Resume thread
            this.m_ThreadStatus.Resume();
            //Set controls Status
            //this.SetControlsEnable(false);
            this.btnRun.Enabled = false;
            this.btnPause.Enabled = true;
            this.btnResume.Enabled = false;
            this.btnStop.Enabled = true;
            this.timer.Start();
        }

        private void btnStop_Click(object sender, System.EventArgs e)
        {
            //Stop thread
            this.m_ThreadStatus.Interrupt();
            //Set controls Status
            this.SetControlsEnable(true);
            this.m_EngineCheckBox.Enabled = true;
            this.btnRun.Enabled = true;
            this.btnPause.Enabled = false;
            this.btnResume.Enabled = false;
            this.btnStop.Enabled = false;
            this.timer.Stop();
        }

        private void timer_Tick(object sender, System.EventArgs e)
        {
            if (!this.m_ThreadStatus.IsFinished)
            {
                this.lblProcessingFile.Text = "File: " + this.m_ThreadStatus.ProcessingFile;
                this.lblFilePercentage.Text = (int)(this.m_ThreadStatus.FilePercentage * 100) + "%";
                this.FileProgressBar.Value = (int)(this.m_ThreadStatus.FilePercentage * 100);

                this.lblProcessingEntry.Text = "Entry: " + this.m_ThreadStatus.ProcessingEntry;
                this.lblEntryPercentage.Text = (int)(this.m_ThreadStatus.EntryPercentage * 100) + "%";
                this.EntryProgressBar.Value = (int)(this.m_ThreadStatus.EntryPercentage * 100);
            }
            else
            {
                this.btnStop_Click(sender, e);
                this.lblProcessingFile.Text = "File: Over!";
                this.lblFilePercentage.Text = "100%";
                this.FileProgressBar.Value = 100;

                this.lblProcessingEntry.Text = "Entry: Over";
                this.lblEntryPercentage.Text = "100%";
                this.EntryProgressBar.Value = 100;
                MessageBox.Show("Task [" + this.lblTitle.Text + "] Completed!", "Task Completed");
            }
        }

        public void OnClosing()
        {
            if (this.m_ThreadStatus == null)
                return;

            if (!this.m_ThreadStatus.IsFinished)
            {
                this.m_ThreadStatus.Interrupt();
            }
        }


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -