Is it imperative I use Application.Run(Form) in a Forms applicatio

G

Guest

Apologies for the cross-group post here, but I wasn't sure of the best group
to pose my question to ...

I have developed a small API for taking care of a lot of boiler plate stuff
in a multi formed windows application, for example setting up a messaging
thread framework.

New Forms, in the appllication using the API, are subclassed to a Form
contained within the API, and they are controlled (controlled in this
instance means, kept alive, displayed and hidden) at runtime by a thread
whose responsibility is this sole task.

In order to run the application, one also needs to further subclass an item
(BaseFormsApplicationStartup) contained within the API, whose required
parameter is the main Form of the application; for example ...

/ ******************************************************/
public class Startup : BaseFormsApplicationStartup
{
public Startup() : base(new MainUI())
{
AddDialog(new MessageWindow());
AddDialog(new GraphWindow());
AddDialog(new NetworkWindow());
DisplayMainApplicationDialog();
}
[STAThread]
static void Main() { new Startup(); }
}
/ ******************************************************/

The members AddDialog(BaseMessageApplicationWindow) and
DisplayMainApplicationDialog() are defined in the abstract class
BaseFormsApplicationStartup.

AddDialog simply places the application's Form under the control of a
DialogManager object. DisplayMainApplicationDialog, results (eventually) in
an instantiation of the following class for displaying the Form.

/ ******************************************************/
internal sealed class DialogDisplayThread
{
/// <summary>Internal Thread object</summary>
private Thread t = null;
/// <summary>
/// Internal reference to the Form that owns the Thread
/// </summary>
private Form m_TheForm = null;
/// <summary>Constructor</summary>
/// <param name="f">The System.Windows.Forms.Form to display</param>
internal DialogDisplayThread(Form f)
{
m_TheForm = f;
t = new Thread(new ThreadStart(ThreadProc));
t.Name = f.Name + "DisplayThread";
t.IsBackground = true;
t.Start();
}
/// <summary>The ThreadStart method.</summary>
internal void ThreadProc() { m_TheForm.ShowDialog(); }
}
/ ******************************************************/

NOTE : I've used Form.ShowDialog() as opposed to Form.Show() because
the former is a blocking call, whilst the latter is not and as
soon as it
finishes, the Thread dies, which ultimately results in the Form
being
destroyed.

The point of all of this is that, I do not ever make use of
Application.Run(Form). I do not see this as a problem in itself, however, I
do have a problem in that my main application Form in a particular
implementation (making use of the API) is not displaying label text correctly.

I fire up the application and the Form is displayed, however where there are
System.Windows.Forms.Label controls on the Form, the text is not displayed,
and the control itself is completely transparent (through to the desktop or
underlying window, etc.), until I move the Form and cause an OnPaint event.
This behaviour continues on the form if it should be covered and then
uncovered, this OnPaint does not appear to affect the Label objects.

I have a sneaking suspicion that the problem would "go away" should I make a
call to Application.Run() passing in my main Form, but I'd rather know what
is going wrong so that I can address the issue rather than crowbarring the
API.

Thanks in advance ... if you want more info please do not hesitate to enquire.


Of all words of tongue and pen, the saddest are: "It might have been"
 
T

Tim_Mac

hi,
there is a good explanation of what Application.Run actually does in
this article on codeproject:
http://www.codeproject.com/csharp/begininvoke.asp

the whole thing isn't relevant, but there is a section on
Application.Run() which i think will help your situation.

the docs say that Application.Run() "Begins running a standard
application message loop on the current thread, without a form". i'd
say this is the explanation for your controls not rendering properly.
having said that, i remember reading an article some time ago about
getting away with calling ShowDialog instead of Application.Run, maybe
that's only if you have one form though...

going by the docs anyway, i would want all my apps to have a standard
application message loop, even if i'm not an expert on what that does!

tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top