c# - Creating a Form and using Form.ShowDialog on a background thread -


using winforms, if i'm on thread not "main" ui thread can safetly

  1. create form,
  2. call showdialog on form

it seems obeying rule of: winforms controls must modified on thread created in.

from of reading i've done seems showdialog create own message pump don't need worry form being created on thread has message pump.

the background of question callback i'd display winforms ui, don't have access other ui use invoke main thread.

that's correct, albeit pretty important call thread's setapartmentstate() method switch thread sta. important many ui operations, including clipboard, drag , drop , shell dialogs. , have crummy z-order problem when form create on thread not in foreground , hides behind window. or has nasty habit of do move in foreground when user doesn't expect , grab mouse click or keystroke unexpectedly.

these hard problems fix, make app flaky. there's no reason not have reference invoke to, can pass class way how. you've got application.openforms[0] fall on, if necessary.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -