471,570 Members | 1,632 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

loading form from another thread

Hello

i have main mdi parent window from which i want to load a form, but
during creating form object and later calling its Show method i want
to display progress and have the main window responsive. But the problem is
that i cannot load form from another thread, when i try to set its
MdiParent property to main window, i get message that parent and child
cant be on separate threads. I could invoke Show without setting MdiParent,
but when i do that the window dont show up cause the thread terminates
after calling Show, and if i try to suspend it, i get only a part of my
form,
which is not responding. I know that this child form must have a message
loop. For now i create and set whole needed properties of window in separete
thread, and just calling Show in main thread, and it works.
But the best for me would be something like that: i create and invoke Show
on separete
thread, and later eventually i link somehow my child window with parent and
its thread.
thanks for any advices
best regards
roman
Feb 17 '06 #1
5 3087
Roman wrote:
i have main mdi parent window from which i want to load a form, but
during creating form object and later calling its Show method i want
to display progress and have the main window responsive. But the problem is
that i cannot load form from another thread, when i try to set its
MdiParent property to main window, i get message that parent and child
cant be on separate threads. I could invoke Show without setting MdiParent,
but when i do that the window dont show up cause the thread terminates
after calling Show, and if i try to suspend it, i get only a part of my
form, which is not responding.


<snip>

I don't believe you can do the UI part of what you want on a different
thread. However, what exactly is taking a long time when you're
creating the form? Is it doing stuff like fetching from a database? If
so, you could put *that* part into another thread, then create the form
itself on the main UI thread when the rest of the work has been done.

Jon

Feb 17 '06 #2
I don't believe you can do the UI part of what you want on a different
thread. However, what exactly is taking a long time when you're
creating the form? Is it doing stuff like fetching from a database? If
so, you could put *that* part into another thread, then create the form
itself on the main UI thread when the rest of the work has been done.


the problem is that i want to load not the forms i know, but the foreign
forms that i cant make any assumptions about. i think the most workload
there will be placed in load event of the form. i thought about calling load
handlers myself from loading separate thread but, they might also need
some controls ready and loaded, which means i probably should call it only
after form
is displayed by show. i was just wonder if it is possible to fully create
form
in other thread and then link it somehow to main ui thread
regards
roman
Feb 18 '06 #3
Roman <dz************@poczta.onet.pl> wrote:
I don't believe you can do the UI part of what you want on a different
thread. However, what exactly is taking a long time when you're
creating the form? Is it doing stuff like fetching from a database? If
so, you could put *that* part into another thread, then create the form
itself on the main UI thread when the rest of the work has been done.


the problem is that i want to load not the forms i know, but the foreign
forms that i cant make any assumptions about. i think the most workload
there will be placed in load event of the form. i thought about calling load
handlers myself from loading separate thread but, they might also need
some controls ready and loaded, which means i probably should call it only
after form is displayed by show. i was just wonder if it is possible to fully
create form in other thread and then link it somehow to main ui thread


I don't believe it is - unless there's some devious call in the Win32
API to "reparent" a UI in a different thread.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 18 '06 #4
> I don't believe it is - unless there's some devious call in the Win32
API to "reparent" a UI in a different thread.


ok, thanks for you answer : )
lukasz cygan (roman)
Feb 18 '06 #5
As an implementation idea - you could use events - i.e. when the call finds
it needs to create a form it simply fires the event (indicating "what" on
the event args); to existing UI can catch this, Invoke to itself (to switch
threads) and then create the form. This keeps UI in the UI and data in the
data-tier.

Perhaps ;-0

Marc
Feb 18 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.