How can I tell if my form was started using Application2?

J

jonfroehlich

This question involves the OpenNetCF SDF.

Is there a straightforward way to determine whether a form was started
using the SDF Application2 class? That is, Application2.Run(new form())
rather than Application.Run(new form())

I thought maybe I could use the Application2.MessageLoop property;
however, this is not set immediately by the SDF. I inspected the
Application2 source code and saw that the messageLoop variable isn't
set to true until after the mainForm visibility is set to true. This
causes the following code:

protected override void OnLoad(EventArgs e)
{
Debug.WriteLine("OnLoad: Application2.MessageLoop: " +
Application2.MessageLoop);
base.OnLoad(e);
}

protected override void OnGotFocus(EventArgs e)
{
Debug.WriteLine("OnGotFocus: Application2.MessageLoop: " +
Application2.MessageLoop);
base.OnGotFocus(e);
}

protected override void OnActivated(EventArgs e)
{
Debug.WriteLine("OnActivated: Application2.MessageLoop: " +
Application2.MessageLoop);
base.OnActivated(e);
}

to initially print out:

OnLoad: Application2.MessageLoop: False
OnActivated: Application2.MessageLoop: False
OnGotFocus: Application2.MessageLoop: False

If I minimize the form (using the "home" button on the phone) and then
refocus it (using the "back" button on the phone), I'm able to force
OnActivated and OnGotFocus to be called. In this case, finally,
MessageLoop is true.

OnActivated: Application2.MessageLoop: True
OnGotFocus: Application2.MessageLoop: True

There has to be a better way!?

Thanks everyone!
 
J

jonfroehlich

As a follow-up question to this; is there any way to tell if my Form
was started using Application2.ShowDialog(form) rather than
form.ShowDialog?

Thanks! again!
 
G

Guest

Modify the SDF source to set a named event or mutex and look at it from your
code. That's the easiest way I can think of.
 
J

jonfroehlich

OK, I didn't know if this feature was already offered by the SDF.

Thanks for the response Chris!

j
 
G

Guest

Nope. This would definitely be a new feature request, though I may look at
implementing it in the next release.
 

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