c# - Possible to construct form on background thread, then display on UI thread -
update: summarize question has boiled down to:
i hoping constructing .net forms , controls did not create window handles -- hoping process delayed until form.show/form.showdialog
can confirm or deny whether true?
i've got large winforms form tab control, many many controls on form, pauses while loading couple seconds. i've narrowed down designer generated code in initializecomponent, rather of logic in constructor or onload.
i'm aware can't trying interact ui on thread other main ui thread, i'd have application pre-load form (run constructor) in background, it's ready display on ui thread instantly user wants open it. however, when constructing in background thread, on line in designer:
this.cmbcombobox.autocompletemode = system.windows.forms.autocompletemode.suggest;
i'm getting error
current thread must set single thread apartment (sta) mode before ole calls can made. ensure main function has stathreadattribute marked on it.
now halfway down designer file, gives me hope in general strategy work. particular line seems trying instantly kick off kind of ole call.
any ideas?
edit:
i think i'm not making myself clear here. delay seems take place during construction of bazillion controls during designer-generated code.
my hope initialization code took place without trying touch real win32 window objects since form hasn't been shown yet.
the fact can set (for example) label texts , positions background thread gave me hope true. may not true properties.
the answer no.
if create window handle on thread other gui thread can never show it.
edit: possible create forms , controls , display them in thread other main gui thread. of course if can access multi threaded gui thread created it, possible. – ashley henderson
you need perform heavy lifting on bg thread , load data gui widget
Comments
Post a Comment