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

  • 相关阅读:
    day06 字典、元组、set的方法及常用操作
    python makestrans translate
    python 中locals() 和 globals()
    threading.local()
    进程 线程 协程
    微信机器人
    flask
    python is ==
    Beautiful Soup 4.4.0 基本使用方法
    12306
  • 原文地址:https://www.cnblogs.com/quietwalk/p/1846457.html
Copyright © 2011-2022 走看看