multithreading - Can't create form in another thread C# -


i built c# program open other forms using multithread (i use because take time load forms) , portal. problem when call create specific form in main thread success , fine, when call specific form in thread "specified cast in invalid" exception. throw in showdialog commands means there not problem in constructor or something. can't public code because built on computer doesnt have internet connection or usb access amd there lot of lines wom't rewirte here :)

thank you

but when call specific form in thread "specified cast in invalid" exception. throw in showdialog commands...

the problem cast. shouldn't doing casting in showdialog method, that's bound wrong. can't tell how fix though because can't see code.

you reason can't post code because can't figure out way of getting off computer wrote on, , it's "complicated , long". that's first clue haven't put enough effort attempting debug problem yourself. first thing when have problem code (and before asking people help) create simple, self-contained example in new, empty project. idea remove complicated , non-essential in order short snippet of code easy debug , not being curiously affected. if had done that, have posted short, self-contained example easily. or, might not have needed ask question @ all, because process of generating sample makes solution obvious.

beyond that, have larger issue: supposed all of ui interaction on single thread. that's why call "main" or "ui" thread. spinning additional background threads idea, should not interact ui. means of forms should created , managed single thread.

there ways around people inevitably try , bring up. yes, can use invoke method background thread allow interact main (ui) thread. shouldn't. if you're having trouble trying multi-threading going.

you whole reason want use multiple ui threads "because take time load forms", that's not reason this. better solution keep in mind old adage fastest code code doesn't run. if forms taking long appear on screen, you're either

  1. trying in form's constructor and/or load event handler
  2. trying run code on computer far slow (in case, multiple threads won't create worthwhile speed boost).

my advice defer as possible later time, after form gets loaded , initialized. speed getting appear on screen. if need then utilize invoke methods set properties on existing form based on initialization work you've done on background thread, that's fine. create , display of forms single thread, or you're in world of pain.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -