Opening a form in a Windows service

  • Thread starter Thread starter Andrew Mueller
  • Start date Start date
A

Andrew Mueller

Hello,

Is there any way to make a form part of a windows service application
and launch it upon double-click of a system tray icon?

I already have the NotifyIcon working and have added an event to it for
the _DoubleClick.

I added a form and tried to open it with:

{Form Name}.ActiveForm.Show();

I am not sure if that is correct or not... I grew up in the VB world and
that is similar to what I am used to using for code to open a form.

Help?

Thanks!

Andrew
 
the correct code for showing the form is

MyForm f = new MyForm();
f.Show();

However, I am unsure how this will work when launching from a Windows
service, as the service is likely to be running as a different user then the
currently logged in user.
 
It looks like the code for the NotifyIcon is not executing.. Here is what I
have:

namespace EPA
{
public class EPAClass : System.ServiceProcess.ServiceBase
{
Log log = new Log(); //This is a log writer. It will write
to file any information I send it
private System.Windows.Forms.NotifyIcon notifyIcon1;

public EPAClass()
{
InitializeComponent();
}

private void InitializeComponent()
{
this.notifyIcon1 = new
System.Windows.Forms.NotifyIcon(this.components);
this.notifyIcon1.Text = "EPA Service";
this.notifyIcon1.Visible = true;
this.notifyIcon1.Icon = new System.Drawing.Icon(GetType(),
"Svc.ico");
this.notifyIcon1.Click += new
System.Windows.Forms.MouseEventHandler(this.notifyIcon1_Click);
}

private void notifyIcon1_Click(object sender,
System.Windows.Forms.MouseEventArgs e)
{
log.WriteToLog("Notify Icon Clicked");
}

}
}



I am not getting the log file written.... Not sure why. There is obviously
more code here, but this should be enough to understand my problem.


Thanks!

Andrew Mueller
 
The problem is that the event for the NotifyIcon is not occuring for a
windows service.... I don't see how that url explains that, unless I am
missing something.

Thanks.

Andrew

PS - If I can get the NotifyIcon to react to a click event or a double-click
event, then everything should be fine. I tested it again by putting code in
these events which would write to the NT Application Event Log, but nothing
happened.
 
Anyone find the fix to this? I to am attempting to have a Windows
Service that can interact with the desktop... the "Interact With
Desktop" option in the service control manager has no effect on the code
executing.



S. Steefel, MCSE
Snr. Software Engineer
 
Back
Top