Home » Uncategorized » Using Background worker in c#

Using Background worker in c#

 private void InitTimer3()
        {
            tmrBack = new System.Windows.Forms.Timer();
            tmrBack.Tick += new EventHandler(tmrBack_Tick);
            tmrBack.Interval = 1000; // in miliseconds
            tmrBack.Start();
        }
        private void tmrBack_Tick(object sender, EventArgs e)
        {
            BackgroundWorker bw2 = new BackgroundWorker();
            bw2.DoWork += new DoWorkEventHandler(bw2_DoWork);
            bw2.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw2_RunWorkerCompleted);
            if (bw2.IsBusy != true)
            {
                bw2.RunWorkerAsync();
            }
        }
        private void bw2_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                add = first +second;
                // time consuming task and hard tasks
            }
            catch { }
        }
        private void bw2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
               text1.text = add;
               //all value related to display on windows do here
            }
            catch { }
        }

Leave a Reply

Subscribe

Join 901 other subscribers