|
-
Apr 3rd, 2011, 05:56 AM
#1
Thread Starter
Hyperactive Member
Custom Event, Cross-Threading problem
Geez this is my fifth thread in like 2 days...
Anyway, the help I get here is awesome and I learn a lot so here is the problem:
When I register a function for an event I created the function is run on another thread apparently.
Code:
Code:
// delegate declaration
public delegate void ChangingHandler(object sender, ProgressArgs pa);
// event declaration
public event ChangingHandler ProgressChanged;
private void StartIt()
{
myworker.ProgressChanged += new Worker.ChangingHandler(myworker_ProgressChanged);
myworker.Start();
}
private void myworker_ProgressChanged(object sender, ProgressArgs e)
{
progressBar.Value = e.Percentage();
}
It refuses to change the value on the progressbar because of that. If I do the same with a backgroundworker it works, why is my changed function executed on another thread and how do I make it execute on the main thread?
Last edited by Cyb3rH4Xter; Apr 3rd, 2011 at 06:00 AM.
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
|