S
Steve Long
Hello,
I hope this question isn't too fundamental. I have a feeling it is. I'm
trying to start a winform app from a windows service written in C#. I
created a class and used it from a windowsforms application and all was
well. But when I try to use the class in the OnStart method of a windows
service, the process I'm trying to start runs but the window never shows up.
Like I said, this may be fundamentally impossible/illogical to do but here's
the basic code I'm using:
public class AppServer
{
public void StartService()
{
string path;
string app;
ProcessStartInfo psi;
string[] settings =
System.Configuration.ConfigurationSettings.AppSettings.GetValues("app");
for (int i = 0; i <= settings.GetUpperBound(0); i++)
{
path = settings.Substring(0, settings.LastIndexOf("\\"));
app = settings.Substring(settings.LastIndexOf("\\") + 1);
Directory.SetCurrentDirectory(path);
psi = new ProcessStartInfo(app);
psi.CreateNoWindow = false;
psi.WindowStyle = ProcessWindowStyle.Normal;
psi.WorkingDirectory = path;
Process.Start(psi);
}
}
}
Any comments much appreciated.
Thanks
Steve
I hope this question isn't too fundamental. I have a feeling it is. I'm
trying to start a winform app from a windows service written in C#. I
created a class and used it from a windowsforms application and all was
well. But when I try to use the class in the OnStart method of a windows
service, the process I'm trying to start runs but the window never shows up.
Like I said, this may be fundamentally impossible/illogical to do but here's
the basic code I'm using:
public class AppServer
{
public void StartService()
{
string path;
string app;
ProcessStartInfo psi;
string[] settings =
System.Configuration.ConfigurationSettings.AppSettings.GetValues("app");
for (int i = 0; i <= settings.GetUpperBound(0); i++)
{
path = settings.Substring(0, settings.LastIndexOf("\\"));
app = settings.Substring(settings.LastIndexOf("\\") + 1);
Directory.SetCurrentDirectory(path);
psi = new ProcessStartInfo(app);
psi.CreateNoWindow = false;
psi.WindowStyle = ProcessWindowStyle.Normal;
psi.WorkingDirectory = path;
Process.Start(psi);
}
}
}
Any comments much appreciated.
Thanks
Steve