Beispiel #1
0
        /// <summary>
        /// Handler que se utiliza para hacer el work
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProcessActivateBrgWrk_DoWork(object sender, DoWorkEventArgs e)
        {
            //DateTime currentDate;
            //int waitTime;
            //string dateStr;
            //List<Price> argumList = e.Argument as List<Price>;
            // DoWorkLoadParams dwParams = e.Argument as DoWorkLoadParams;
            LogProcess logProc = e.Argument as LogProcess;

            BackgroundWorker worker = (BackgroundWorker)sender;

            while (!worker.CancellationPending)
            {
                int maxTimeWaiting  = Convert.ToInt32(txtTimeWait.Text);
                ProcessSimulator ps = new ProcessSimulator(maxTimeWaiting);
                ps.MaxTimeDuration     = Convert.ToInt32(txtTimeWait.Text);
                logProc.ProcessExecute = ps;
                logProc.DtInic         = DateTime.Now;
                Thread.Sleep(ps.RealTimeDuration * 1000);
                logProc.DtFin = DateTime.Now;
                //dateStr = currentDate.ToString("dd/MM/yyyy HH:mm:ss");
                e.Result = logProc;                // esto es para que en el evento progress changed poder atrapar
                                                   // en el metodo ProcessActivateBrgWrk_RunWorkerCompleted
                worker.ReportProgress(0, logProc); // hace que se dispare el evento ProgressChanged
                TimeSpan ts = logProc.DtFin - logProc.DtInic;
                logProc.WaitTime = this.timeWaitLoading - ts.Seconds;
                if (logProc.WaitTime <= 0)
                {
                    logProc.WaitTime = 0;    // espere 1 seg
                }
                int miliSecs = logProc.WaitTime * 1000;
                Thread.Sleep(miliSecs);
            }
        }
Beispiel #2
0
        private void ProcessActivateBrgWrk_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            //string logStr = e.UserState as string;
            LogProcess logProc = (LogProcess)(e.UserState);

            //Console.WriteLine(dateStr);
            txtOutPut.Text += (logProc.ToString() + Environment.NewLine);
        }
Beispiel #3
0
        private void butStart_Click(object sender, EventArgs e)
        {
            LogProcess logProc = new LogProcess();

            if (!processActivateBrgWrk.IsBusy)
            {
                this.timeWaitLoading = Convert.ToInt32(txtTimeWait.Text); // miliseconds
                processActivateBrgWrk.RunWorkerAsync(logProc);            // Start del work
            }
            else
            {
                MessageBox.Show("La tarea esta ejecutando!!!");
            }
        }
Beispiel #4
0
 private void ProcessActivateBrgWrk_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Cancelled)
     {
         MessageBox.Show("The task has been cancelled");
     }
     else if (e.Error != null)
     {
         MessageBox.Show("Error. Details: " + (e.Error as Exception).ToString());
     }
     else
     {
         LogProcess dt = (LogProcess)(e.Result);
         MessageBox.Show("The task has been completed. Results: " + dt.ToString());
     }
 }