?
Solved

how to show a modeless form from a thread

Posted on 2004-03-21
3
Medium Priority
?
465 Views
Last Modified: 2012-06-27
hi
did anybody try to show a form from within a running thread? The form's object is declared as a member of the class that owns the thread and is initialized in the class's constructor. now in the thread's delegate, i call the show method (frm.Show()). Conceptually, since its a modeless show, the form should appear and tne tnread should go on with its work. however, just the border and the title of the form appear but nothing is drawn in the form.

why is that? is there any workaround solution?
0
Comment
Question by:mhdhallak
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 1000 total points
ID: 10644929
Is is easy to understand why this happens - because thread doesn't have message loop.
I am not fun of user-interface threads. My approach is that UI elements should be always created in the main thread. Worker thread should do it's background work calling main thread forms ising Invoke or BeginInvoke. Since I don't like UI threads, I have never try to make them in .NET. After reading your question I tried to find something in .NET which allows to create UI thread, but I think this is not allowed.
So, make al UI work in the main thread. To create medeless form call some main (already existing) form method using Invoke or BeginInvoke. Create modeless form from this method.
0
 
LVL 8

Expert Comment

by:RomanPetrenko
ID: 10656192
Hi,
Take a look on this UI Threading Helper Classes, may be you can get something for your implementation
http://weblogs.asp.net/rosherove/articles/7171.aspx
0
 

Expert Comment

by:Matecocido
ID: 11023202
Use:

Application.Run(aForm) ;

inside thread and all work!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question