Windows interop...

  • Thread starter Thread starter Jacek Jurkowski
  • Start date Start date
J

Jacek Jurkowski

1) How to prevent user to run secound copy of application
on the same mahine? I would like to show dialog
"Already run" instead of launching a secound insrance.
2) Why, if minimized into a notify icon, my application
prevents Windows from shutdown and restart?
I'm handling SessionEnding event and it works fine if
application window is showed to the user but when window
is hidden and notyfy icon is displayed instead, it doesn't
work at all... Windows is not shutting down...
3) How to enable WindowsService option "Allow interact with dektop"
from service installer? Without that option checked my service
desnt show notify icon ... I couldn't find that option enywhere ...
 
use the following code in order to start the application.

[System.Diagnostics.DebuggerStepThrough()]

[STAThread]

static void Main()

{


Application.Run(new Form1());

Application.Exit();

Environment.Exit(0);

}
 
Windows Forms Tips and Tricks shows you how to prevent a second copy running
and bring the first copy to the foreground.

Instead of hiding the main application window when the notifyicon is shown,
move it off screen and make it very small so that it cannot be seen. This
will allow the message loop to keep running.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Instead of hiding the main application window when the notifyicon is
shown,
move it off screen and make it very small so that it cannot be seen. This
will allow the message loop to keep running.

Why? I'm affraid that my not hidden window will capture the focus
in windows window queue and user will be confused "where the focus gone".
Why hiding window is stoppinh a "message loop"?
 
Hi,


Jacek Jurkowski said:
1) How to prevent user to run secound copy of application
on the same mahine? I would like to show dialog
"Already run" instead of launching a secound insrance.
http://www.yoda.arachsys.com/csharp/faq/#one.application.instance

2) Why, if minimized into a notify icon, my application
prevents Windows from shutdown and restart?
I'm handling SessionEnding event and it works fine if
application window is showed to the user but when window
is hidden and notyfy icon is displayed instead, it doesn't
work at all... Windows is not shutting down...

Being in the systray is not inpediment to shutdown, are you processing the
Close event?



cheers,
 
2) Why, if minimized into a notify icon, my application
Being in the systray is not inpediment to shutdown, are you processing
the Close event?


Yes I did but seems to SessionEnding event doesn't raise
in that state ...

Trick with hoding window outside the screen doesn't help
anyway ... there is no way to close my application with
NotifyIcon displayed ...
 
Hi,

Trick with hoding window outside the screen doesn't help
anyway ... there is no way to close my application with
NotifyIcon displayed ...

The bad thing about the window solution is that it's displayed using
alt+tab ( this can be solved though )
what I don't understand is what is the problem with the systray , I have a
couple of application running like this and I have never had a complain from
the client that he can not shutdown, he does it everydays cause he has the
theory that it's good for the computers :)


I will run them when I get home and let you know what happens


cheers,
 
Jacek,

In your Closing event, are you doing something like this to iconise the form
when it is closed?
private void MainForm_Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
Hide();
}
if so then this event will be firing before the SessionEnding event, and
prevent SessionEnding (because you have prvented the form from closing).

A solution is to change the above to:

if (this.Visible)
{
e.Cancel = true;
Hide();
}

Now the form will iconise if it is fully open, but if it's already iconised
then Closing won't be cancelled and SessionEnding gets a chance.
The downside is that now you can't log off immediately if the form is fully
open, but if the normal state is iconised that won't be a big problem.

Chris
 
Using Hide() in Main application window doesn't actually
hide it bu releases it and application is ending...
 
Back
Top