|
-
September 13th, 2006, 07:42 PM
#1
BeginInvoke / Updating Controls
Hi,
I think lots of them might have answered this topic. I am still struggling to understand this. I tried but somewhere i am sure i am doing mistake. I am kind of able to know the concept but want to implement that. This is basically updating UI controls of main thread when some other task is occuring in worker thread.
I want to update the progress bar control in the main form. From the form i am calling a method of different class in a different file. From there i would like to update the progress control in the main form.
Code:
//Assuming
AA.cs // File Name
public partial class MainForm: Form
{
Thread m_Thread = null; // Thread
public MainForm()
{
//Constructor
//Do something...
COtherclass other = new COtherclass(); //Class in Different File
}
private void OnButtonClick()
{
m_Thread = new Thread(new ThreadStart(ThreadFunction));
m_Thread.Start();
}
private void ThreadFunction()
{
other.LongFunction(); // Function which takes long time
}
private void UpdateProgressBar(int iCount)
{
progressBar.Value = iCount; // Update the progress Bar
}
}
//Assuming
BB.cs // Second File Name
public class COtherclass
{
public COtherclass()
{
//Constructor
//Do something...
}
public void LongFunction()
{
// Do some time consuming task
// Update the progress bar in the Mainform
// by calling UpdateProgressBar(...) method
}
}
Having this situation ,
How can i declare the delegate ?
How to implement BeginInvoke?
do i need the method Invokerequired()?
I saw in some forums implementing Sleep(). Do we need that?
Please help me to understand this and also help me to insert the relevant pseudo code in this sample. Once again i thank in advance and your help is greatly appreciated.
"Dont Forget to rate if it helped"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|