|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Asynchronous Invoke and the UI thread (using delegates)Hello,
After studying some of the available resouces ( http://msdn.microsoft.com/msdnmag/issues/04/05/BasicInstincts/default.aspx) I can see that it is forbidden to modify the UI directly from a secondary worker thread. What I was wondering was whether I could instantiate a form within my secondary thread, get some user input and carry on until I finished? Does this break any rules of good programming conduct? "brisers" <bris***@discussions.microsoft.com> schrieb That's possible. The only condition: The Form must not have any relation to > Hello, > > After studying some of the available resouces > ( > http://msdn.microsoft.com/msdnmag/issues/04/05/BasicInstincts/default.aspx) > I can see that it is forbidden to modify the UI directly from a > secondary worker thread. What I was wondering was whether I could > instantiate a form within my secondary thread, get some user input > and carry on until I finished? Does this break any rules of good > programming conduct? Forms created in other threads. Armin
Show quote
Hide quote
"Armin Zingler" <az.nospam@freenet.de> schrieb "no relation" does not mean, it mustn't have a reference, but there mustn't > "brisers" <bris***@discussions.microsoft.com> schrieb > > Hello, > > > > After studying some of the available resouces > > ( > > http://msdn.microsoft.com/msdnmag/issues/04/05/BasicInstincts/default.aspx) > > I can see that it is forbidden to modify the UI directly from a > > secondary worker thread. What I was wondering was whether I could > > instantiate a form within my secondary thread, get some user input > > and carry on until I finished? Does this break any rules of good > > programming conduct? > > > That's possible. The only condition: The Form must not have any > relation to Forms created in other threads. be a child/parent/owner relation. In the new thread you can write: sub threadmain application.run(new OtherForm) end sub The thread ends as soon as the Form is closed. Armin Armin,
No, I don't think it breaks any rules of programming conduct. The code you provided will work fine provided that you understand that OtherForm should remain completely independent from the other forms of your application running on the main UI thread. However, without knowning exactly what you're wanting to do I question the need for another UI thread. Can't you collect all of the inputs your worker thread needs before you start it? That way the worker thread doesn't need any user interaction. The worker thread can use Control.Invoke to marshal the execution of a delegate onto the main UI thread as needed to communicate back to forms inside your application. Brian Armin Zingler wrote: Show quoteHide quote > "no relation" does not mean, it mustn't have a reference, but there mustn't > be a child/parent/owner relation. > > In the new thread you can write: > > > sub threadmain > > application.run(new OtherForm) > > end sub > > The thread ends as soon as the Form is closed. > > > Armin "Brian Gideon" <briangid***@yahoo.com> schrieb That's what I wrote.> Armin, > > No, I don't think it breaks any rules of programming conduct. The > code you provided will work fine provided that you understand that > OtherForm should remain completely independent from the other forms > of your application running on the main UI thread. > However, without knowning exactly what you're wanting to do *I* don't want to do anything. :-)Armin Yeah, somehow I totally confused you with the OP. Sorry about that.
My post was not directed at you :) Brian Armin Zingler wrote: Show quoteHide quote > "Brian Gideon" <briangid***@yahoo.com> schrieb > > Armin, > > > > No, I don't think it breaks any rules of programming conduct. The > > code you provided will work fine provided that you understand that > > OtherForm should remain completely independent from the other forms > > of your application running on the main UI thread. > > That's what I wrote. > > > However, without knowning exactly what you're wanting to do > > *I* don't want to do anything. :-) > > > Armin Add the following to your form and you can update its controls from another
thread: CheckForIllegalCrossThreadCalls = False Show quoteHide quote "brisers" <bris***@discussions.microsoft.com> wrote in message news:E8D8E52A-D461-4F77-837E-3DC7D5057A9E@microsoft.com... > Hello, > > After studying some of the available resouces > ( > http://msdn.microsoft.com/msdnmag/issues/04/05/BasicInstincts/default.aspx) I > can see that it is forbidden to modify the UI directly from a secondary > worker thread. What I was wondering was whether I could instantiate a form > within my secondary thread, get some user input and carry on until I > finished? Does this break any rules of good programming conduct? "Prester John" <presterj***@comcast.net> schrieb This doesn't solve the problem. It only makes the runtime ignores faults.> Add the following to your form and you can update its controls from > another thread: > > CheckForIllegalCrossThreadCalls = False Armin
HttpWebRequest using Certificates
Pulling specific words from a string Basic question Enumerate members of Administrators Group (AD) MenuItem.RadioCheck Radio Button Grouping in vb/VS 2005 Web service question How to use my default mail client to mail any file? Accessing Mdi Child Form Control form another one making a SOAP connection persist |
|||||||||||||||||||||||