Wednesday, January 19, 2005

Ian Griffiths on UI Thread

The following message was one of Ian Griffiths's posts on discuss.develop.com.

Alois Reisinger wrote:
> Once again some ui thread question.
> Does all the WinForms have to be on the same thread? (i think no).

No - each top level form is allowed to be on its own thread. While people often use the term "The UI thread" as a convenient shorthand, it's slightly misleading, as a Windows Forms application can in fact have several UI threads. (Although in practice a lot of Windows Forms applications only use one thread as a UI thread. In these cases, it makes perfect sense to refer to "the UI thread.")

Note that it's only with top-level windows that you can do this. Everything inside a particular top-level window has to live on the same thread as that top-level window.

Which leads us onto your next question:
> Could there be a problem, if i have a newly created form that
> should be inserted as a child into a mdi parent if they (parent
> and child) were created on different threads?

Yes, that would be a problem.
Here's why. When you add a form as an MDI child of another form, you are effectively doing two things: you are adding the child to the parent's MdiChildren collection, and you are also setting the child's MdiParent property. Doing one of these implicitly does the other for you. If you write this:

child.MdiParent = parent;

then this has the implicit side effect of adding the child to the parent's MdiChildren. Or if you do this:

parent.MdiChildren.Add(child);

then that has the implicit side effect of setting the child's MdiParent property to refer to the parent.

If these two forms have different UI threads, then whichever thread you choose to set up the parent/child association on, it'll be the wrong thread for one or other of them.

And the same problem applies for normal non-MDI parenting too. (Both for Forms and for any other control. And yes, you can nest a form inside another form without resorting to MDI.)

4 Comments:

At 5:13 PM, Blogger ninest123 said...

louis vuitton outlet, ugg boots, ray ban sunglasses, oakley sunglasses, louis vuitton outlet, longchamp pas cher, prada outlet, polo ralph lauren outlet, nike outlet, chanel handbags, louboutin outlet, longchamp outlet, louis vuitton, nike air max, cheap oakley sunglasses, longchamp outlet, jordan shoes, louis vuitton, nike free, tiffany and co, tory burch outlet, prada handbags, replica watches, nike roshe run, longchamp, louboutin, air max, ralph lauren pas cher, christian louboutin outlet, replica watches, louis vuitton, nike air max, kate spade outlet, louboutin pas cher, nike free, oakley sunglasses, sac longchamp, oakley sunglasses, polo ralph lauren outlet, louboutin shoes, uggs on sale, ray ban sunglasses, ray ban sunglasses, burberry, gucci outlet, oakley sunglasses, tiffany jewelry, ugg boots, air jordan pas cher, michael kors

 
At 5:15 PM, Blogger ninest123 said...

coach outlet, ugg boots, vans pas cher, michael kors, hollister, coach purses, nike air max, ray ban uk, sac guess, ray ban pas cher, mulberry, true religion outlet, hermes, michael kors outlet, oakley pas cher, true religion jeans, lacoste pas cher, ugg boots, michael kors outlet, michael kors outlet, true religion jeans, nike free run uk, tn pas cher, michael kors, nike air max, burberry, vanessa bruno, lululemon, nike roshe, nike air max, ralph lauren uk, coach outlet, north face, replica handbags, nike blazer, converse pas cher, michael kors outlet, timberland, michael kors, abercrombie and fitch, hollister pas cher, true religion jeans, air force, burberry outlet online, michael kors, michael kors outlet, new balance pas cher, north face, kate spade handbags, hogan

 
At 5:19 PM, Blogger ninest123 said...

mont blanc, nike air max, babyliss, mcm handbags, louboutin, herve leger, ghd, hollister, celine handbags, lancel, new balance, nike trainers, valentino shoes, nfl jerseys, reebok shoes, soccer shoes, oakley, vans shoes, p90x workout, soccer jerseys, nike huarache, converse outlet, nike roshe, abercrombie and fitch, bottega veneta, north face outlet, beats by dre, birkin bag, instyler, gucci, mac cosmetics, chi flat iron, ferragamo shoes, insanity workout, ralph lauren, nike air max, jimmy choo shoes, longchamp, wedding dresses, asics running shoes, vans, hollister, timberland boots, iphone cases, baseball bats, hollister, giuseppe zanotti, north face outlet, ray ban, lululemon

 
At 5:24 PM, Blogger ninest123 said...

montre pas cher, moncler outlet, moncler, karen millen, moncler, supra shoes, ugg pas cher, wedding dresses, swarovski, moncler, sac louis vuitton pas cher, doudoune canada goose, moncler, louis vuitton, pandora charms, canada goose, ugg,uggs,uggs canada, swarovski crystal, marc jacobs, hollister, moncler, toms shoes, louis vuitton, ugg boots uk, louis vuitton, canada goose uk, coach outlet, louis vuitton, moncler, canada goose, pandora charms, links of london, moncler, canada goose, canada goose outlet, pandora jewelry, juicy couture outlet, canada goose, thomas sabo, juicy couture outlet, pandora jewelry, bottes ugg, canada goose outlet, ugg,ugg australia,ugg italia, replica watches

 

Post a Comment

<< Home