|
-
Aug 12th, 2012, 09:05 PM
#11
Re: Forms Colliding
I specifically state in my Blog post:
When can’t you use default instances?
3. You need to access a form from a secondary thread.
The whole point of the DoWork event handler is that it's executed on a secondary thread. If the DoWork event handler is executed on a secondary thread then every method you call from it, e.g. Class1.run, is executed on that same secondary thread, which is the whole point. By using the default instance there you are using the default instance specific to that thread, which is a completely different object to the one that was created and displayed on the UI thread in the first place. Your code is working perfectly, i.e. it is updating the ProgressBar on the default Form1 instance for the current thread. The problem is that that is not the Form1 instance whose ProgressBar you want to update because that is not the Form1 instance that you displayed to the user. This is a perfect example of why many people, myself included, think that we would be better off without default form instances.
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
|