multithreading - Exception when trying to show a form created in another (background) thread on .netCF with OAC -
in multi form .netcf 3.5 application i'm trying create forms in background while user occupied previous form. we're using orientation aware control in project
we use wrapper class (formcontroller
) (please let me know if i'm using wrong terminology) keep static references different forms in our application. since want create them once.
at moment forms created first time used. since time consuming operation we'd in background while user
application.run(new formcontroller.startui()); class formcontroller{ private static object lockobj = new object(); private static bool secisloaded = false; private static startform startform = new startform(); private static secform m_secform; static secform formworkorderlist { { createsecform(); return m_secform; } } private static void startui(){ startform.show(); threadstart tssecform = createsecform; thread trsecform = new thread(tssecform); trsecform.priority = threadpriority.belownormal; trsecform.isbackground = true; trsecform.start(); return startform; } private static void createsecform() { monitor.enter(lockobj); if(!secisloaded){ m_secform = new secform(); secisloaded = true; } monitor.exit(lockobj); } private static void gotosecform() { secform.show(); startform.hide(); }
when call gotosecform()
program throws excepton on secform.show()
exection hresult: 2146233067 , no other valuable information.
the stacktrace of exception is:
on microsoft.agl.common.misc.handlear(pal_error ar) on system.windows.forms.control.suspendlayout() on b..ctor(orientationawarecontrol control) on clarius.ui.orientationawarecontrol.applyresources(cultureinfo cultureinfo, boolean skipthis) on clarius.ui.orientationawarecontrol.applyresources() on clarius.ui.orientationawarecontrol.onload(eventargs e) on clarius.ui.orientationawarecontrol.c(object , eventargs ) on system.windows.forms.form.onload(eventargs e) on system.windows.forms.form._setvisiblenotify(boolean fvis) on system.windows.forms.control.set_visible(boolean value) on system.windows.forms.control.show()
i'm quite qlueless what's going wrong here. can me out?
or there better ways load forms in background?
let me know if more information needed.
you can't create forms (or safely manipulation of controls or forms) in background threads. need created on same thread message pump running on - way windows forms work.
creating form shouldn't in expensive task. advice perform expensive computations needed display form in background thread, , pass result of computations main message pump in order create , display form itself.
(half way through writing realised question windows mobile, i'm 99% sure above still applies in situation)
Comments
Post a Comment