zoukankan      html  css  js  c++  java
  • windows mobile多线程示例

    AuthorQuietwalk

    Date2010-10-9

     

    private static bool bThreadEnd;

    private Thread workThread;

    DateTime dtStart;

    DateTime dtEnd;

     

      #region download

            private void miDownLoad_Click(object sender, EventArgs e)

            {

                this.btnSend.Visible = false;

                this.btnReceiveFile.Visible = true; //使能下载按钮

                this.btnReceiveFile.Focus();

                this.statusBar1.Text = "";

            }

            //下载并接收文件

            //调用WebService 将应用服务器上的 Zip 包转换成二进制流发送出来

            //调用设备本地的代码接收并存放

            private void btnReceiveFile_Click(object sender, EventArgs e)

            {

              

                //*******************************************

                this.timer1.Enabled = true;

                this.btnReceiveFile.BackColor = Color.Yellow;

                this.statusBar1.Text = "正在下载数据,请稍候。。。";

                dtStart = DateTime.Now;

                workThread = new Thread(new ThreadStart(ReceiveAndSaveFile));

                workThread.Start();

     

           

            }

     

            private void ReceiveAndSaveFile()

            {

     

                bThreadEnd = false;

                GPRSTest.jwsHelloWorld.HelloWordImplService sv = new HelloWordImplService();

                QuietwalkClassLibrary.CommonFunctions.SaveFile(sv.convertZip2ByteArray());//返回的是执行后成功与否,但这里不需要接收此参数

     

                bThreadEnd = true;

            }

     

            private void timer1_Tick(object sender, EventArgs e)

            {

               

                if (!bThreadEnd)//如果线程没有结束

                {

                    if (this.progressBar1.Value == progressBar1.Maximum)//到最大了之后再从0开始

                    {

                        this.progressBar1.Value = 0;

                    }

     

                    this.progressBar1.Value += 5;

     

                 

                }

                else//线程结束了

                {

                    this.timer1.Enabled = false;//关闭计时器

                    this.progressBar1.Value = this.progressBar1.Maximum;

     

                    dtEnd = DateTime.Now;

     

                    if (QuietwalkClassLibrary.CommonFunctions.bDoneStatus)

                    {

                        this.statusBar1.Text = this.statusBar1.Text = "下载并存储到设备所用时间:  " + QuietwalkClassLibrary.CommonFunctions.GetTimeSpan(dtStart, dtEnd).ToString() + "--" + DateTime.Now.ToShortTimeString();

                    }

                    else

                    {

                        this.statusBar1.Text = "下载失败!";

                    }

                   

                  

     

                }

     

            }

            #endregion download

  • 相关阅读:
    tail命令语法
    正则表达式示例
    HTTP状态码对照表 HTTP response codes
    linux 源的配置更新
    shell基本语法
    谁偷走了程序员的时间??
    Spring Data JPA 简单查询-接口方法
    GET和POST两种基本请求方法的区别
    您是怎样度过人生的低潮期的
    树莓派中Docker部署.Net Core 3.1 (一)
  • 原文地址:https://www.cnblogs.com/quietwalk/p/1846457.html
Copyright © 2011-2022 走看看