zoukankan      html  css  js  c++  java
  • backgroudWork使用案例

    #region 删除垃圾文件过程

    /// <summary>
    /// 删除垃圾文件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btn_delete_Click(object sender, EventArgs e)
    {

    //开启后台查询线程,即引发新线程的事件,同时提供事件参数
    //注意backgroundWork中的DoWork事件,并编写事件处理程序,
    //并提供事件数据,因为后台线程是无法直接访问主线程的数据的,
    //同时还需要编写backgroundWork中的RunWorkerCompleted事件处理程序,
    //以通知前端主线程

    string doWorkArguments = cmb_fileFolderDerectory.Text;
    backgroundWorker1.RunWorkerAsync(doWorkArguments);

    //开启处理进程条
    this.progressBar1.Visible = true;
    timer1.Interval = 100;
    this.timer1.Tick += new EventHandler(Timer1_Tick);
    timer1.Start();


    }

    /// <summary>
    /// 用计时器体现查询进度表,非真实进度,仅是对用户的提示,因后台查询进度暂无法计算衡量
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Timer1_Tick(object sender, EventArgs e)
    {

    if (!finishedFlag)
    {
    if (progressBar1.Value == progressBar1.Maximum)
    {
    progressBar1.Value = 1;
    }
    else
    {
    this.progressBar1.Value++;
    }

    }
    else
    {
    this.timer1.Stop();

    }

    }

    /// <summary>
    /// 删除文件的后台进程
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
    FilesOperate f = new FilesOperate();
    int deleteFilesAmount = f.DeleteUserFile(e.Argument.ToString());

    }

    private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {

    this.finishedFlag = true;
    //完成后进程条不可见
    this.progressBar1.Visible = false;
    MessageBox.Show("删除垃圾文件" + this.deleteFilesAmount + "个", "删除提示");
    }

    #endregion

  • 相关阅读:
    tmp
    GO语言中使用OpenCV
    The OpenCV Coding Style Guide
    下载tree命令的源代码
    convention over configuration 约定优于配置 按约定编程 约定大于配置 PEP 20 -- The Zen of Python
    tmp
    起步依赖
    Spring Boot Dubbo Dubbok spring cloud
    pug.compile() will compile the Pug source code into a JavaScript function that takes a data object (called “locals”) as an argument.
    request /a?b= /a/?b=
  • 原文地址:https://www.cnblogs.com/windy3417/p/14122753.html
Copyright © 2011-2022 走看看