/// <summary> /// Add a processing item to the listview /// </summary> /// <param name="name">Name of item</param> /// <param name="message">IvsMessage of item</param> public void AddProcess(string name, string message, CommonData.ProgressBarType progressBarType) { ListViewItem item = new ListViewItem(message); item.SubItems.Add(this.CreatedDate); item.Name = name; listViewProgress.Items.Add(item); // Embed the ProgressBar if (progressBarType == CommonData.ProgressBarType.Marquee) { MarqueeProgressBarControl progressBar = new MarqueeProgressBarControl(); progressBar.Name = name; progressBar.Tag = CommonData.ProgressBarType.Marquee.ToString(); this.lstProgressBar.Add(progressBar); this.listViewProgress.AddEmbeddedControl(progressBar, 2, this.NumOfProcess - 1); } else { ProgressBarControl progressBar = new ProgressBarControl(); progressBar.Properties.Step = 1; progressBar.Properties.ShowTitle = true; progressBar.Properties.PercentView = true; progressBar.Properties.Maximum = 100; progressBar.Properties.Minimum = 0; progressBar.Name = name; progressBar.Tag = CommonData.ProgressBarType.Progress.ToString(); this.lstProgressBar.Add(progressBar); this.listViewProgress.AddEmbeddedControl(progressBar, 2, this.NumOfProcess - 1); } //Add timer to get percent IvsTimer timer = new IvsTimer(); timer.Name = name; timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.Enabled = true; timer.Interval = 500; this.lstTimer.Add(timer); //start timer timer.Start(); }
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { IvsTimer timer = ((IvsTimer)sender); string name = timer.Name; string percent = CommonData.StringEmpty; try { //if (service.GetTaskProgress(CommonData.GetFullPath(DbConfig.TempFolder, name, "txt"), ref percent)) //{ // ProgressBarBaseControl progressBarBase = this.GetProgressBar(this.lstProgressBar, name); // //Tag = 1 - Using marquee bar control // //Tag = 2 - Using progress bar control // if (progressBarBase != null && progressBarBase.Tag != null && progressBarBase.Tag.ToString().Equals(CommonData.ProgressBarType.Progress.ToString())) // { // ProgressBarControl progressBar = (ProgressBarControl)progressBarBase; // if (progressBar != null) // { // int perCent = CommonMethod.ParseInt(percent); // //process task with step by step // if (progressBar.Position < perCent) // { // if (this.InvokeRequired) // { // this.BeginInvoke(new Action(progressBar.PerformStep)); // this.BeginInvoke(new Action(progressBar.Update)); // } // else // { // progressBar.PerformStep(); // progressBar.Update(); // } // } // //process task with progress // if ((perCent > 25 && progressBar.Position < 25) // || (perCent > 50 && progressBar.Position < 50) // || (perCent > 75 && progressBar.Position < 75) // || (perCent == 100)) // { // if (this.InvokeRequired) // { // this.BeginInvoke(new Action<int>(progressBar.Increment), perCent); // this.BeginInvoke(new Action(progressBar.Update)); // } // else // { // progressBar.Increment(perCent); // progressBar.Update(); // } // //finish task // if (perCent == 100) // { // timer.Stop(); // timer.Enabled = false; // } // } // } // } //} } catch (Exception) { timer.Stop(); timer.Enabled = false; } }