KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have the following problem: I have a Form named MainForm. I have a long operation to be taken place on this form. While this long operation is going on, I need to show another from named ProgressForm on top of the MainForm. ProgressForm contains a progress bar which needs to be updated while the long operation is taking place. After the long operation is completed, the ProgressForm should be closed automatically. I have written the following code: using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Threading; namespace ClassLibrary { public class MyClass { public static string LongOperation() { Thread.Sleep(new TimeSpan(0,0,30)); return "HelloWorld"; } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace BackgroungWorker__HelloWorld { public partial class ProgressForm : Form { public ProgressForm() { InitializeComponent(); } public ProgressBar ProgressBar { get { return this.progressBar1; } set { this.progressBar1 = value; } } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using ClassLibrary; namespace BackgroungWorker__HelloWorld { public partial class MainForm : Form { ProgressForm f = new ProgressForm(); public MainForm() { InitializeComponent(); } int count = 0; private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (f != null) { f.ProgressBar.Value = e.ProgressPercentage;
Tags (comma-separated)
Save Edits
Cancel