PC Review


Reply
Thread Tools Rate Thread

Application without Application.Run()

 
 
Marc Ambrosius
Guest
Posts: n/a
 
      26th Sep 2003
Hello,

in our current project we wanted to get into the
application's message loop to catch some messages (e.g.
keyboard events for accelerators). We found several
possibilities (hooks and hot keys are global) and finally
ended up with an application without a call to
Application.Run(), see the following example:

static void Main()
{
int i = 0;
mainForm = new MainForm();
mainForm.Visible = true;

MSG msg = new MSG();
System.Exception exception = null;

while (GetMessage(ref msg, 0, 0, 0) == 1)
{
try
{
TranslateMessage(ref msg);
if (msg.message == 0x101)
{
i++;
mainForm.label1.Text = i.ToString();
}
DispatchMessage(ref msg);
}
catch (System.Exception e)
{
exception = e;
}
}
if (exception != null)
{
MessageBox.Show(exception.ToString(), "Exception");
}
}

One just has to make sure that Application.Exit(); is
called finally.

As nobody here really knows what Application.Run() exactly
does I don't feel very comfortable running a program like
this. Does anybody have an idea if we will encounter any
difficulties, or is our approach possible?

Any idea is appriciated

Marc
 
Reply With Quote
 
 
 
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      26th Sep 2003
That's basically what Application.Run() does - it just goes into a message
pump that exits when the passed-in Form reference become invalid. Your code
looks fine (though how should the app actually die?).

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net

"Marc Ambrosius" <(E-Mail Removed)> wrote in message
news:1e6201c38442$83c6aed0$(E-Mail Removed)...
> Hello,
>
> in our current project we wanted to get into the
> application's message loop to catch some messages (e.g.
> keyboard events for accelerators). We found several
> possibilities (hooks and hot keys are global) and finally
> ended up with an application without a call to
> Application.Run(), see the following example:
>
> static void Main()
> {
> int i = 0;
> mainForm = new MainForm();
> mainForm.Visible = true;
>
> MSG msg = new MSG();
> System.Exception exception = null;
>
> while (GetMessage(ref msg, 0, 0, 0) == 1)
> {
> try
> {
> TranslateMessage(ref msg);
> if (msg.message == 0x101)
> {
> i++;
> mainForm.label1.Text = i.ToString();
> }
> DispatchMessage(ref msg);
> }
> catch (System.Exception e)
> {
> exception = e;
> }
> }
> if (exception != null)
> {
> MessageBox.Show(exception.ToString(), "Exception");
> }
> }
>
> One just has to make sure that Application.Exit(); is
> called finally.
>
> As nobody here really knows what Application.Run() exactly
> does I don't feel very comfortable running a program like
> this. Does anybody have an idea if we will encounter any
> difficulties, or is our approach possible?
>
> Any idea is appriciated
>
> Marc



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
appdata-local-Application Data-Application Data-Application Data infinitum ad nauseum. WHY keepout@yahoo.com.invalid Windows Vista General Discussion 15 16th Sep 2007 01:50 AM
Managed C++: The application failed to initialize properly (0xc000007b).Click on OK to terminate the application. Tommy Vercetti Microsoft VC .NET 4 23rd Mar 2005 08:19 PM
Fail in operating my hardware in web application , makes other windows application startup failure. Ryan.ZhYin Microsoft C# .NET 0 25th Jan 2005 08:34 AM
Please recommend book about design patterns for server application\distrubuted application Julia Microsoft C# .NET 2 11th Dec 2004 01:37 AM
Making more memory available to application?Im making a memory intense application, the application is supposed to open a prettylarge image (about 9200*10200 in 300Dpi) yosh@liquidzone.net Microsoft Dot NET Framework Forms 0 6th Dec 2004 07:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:15 PM.