D
Domleg
Guest
Hello,
I have a service that just needs to start an executable and it starts in memory ok, the executable also runs in memory but the service just hangs with green progress bar and eventually times out with the service didn't respond in a timely fashion error. The service just gets stuck at starting after the error.
Here is the code for the service.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Threading.Tasks;
using System.Timers;
namespace T4CNginxService
{
public class Service1 : ServiceBase
{
private Timer _xginxTimer;
private Process[] serviceNginx = Process.GetProcessesByName("nginx");
private IContainer components = null;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
Task task = Task.Run(delegate
{
_xginxTimer_Elapsed();
});
task.Wait();
}
public void _xginxTimer_Elapsed()
{
try
{
if (serviceNginx.Count() <= 0)
{
EventLog.WriteEntry("Started Nginx Service", EventLogEntryType.Information);
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.WorkingDirectory = "C:\\Program Files (x86)\\Lely\\T4C\\nginx";
Process process = new Process();
processStartInfo.FileName = "C:\\Program Files (x86)\\Lely\\T4C\\nginx\\nginx.exe";
process.StartInfo = processStartInfo;
process.StartInfo.Verb = "runas";
process.Start();
process.WaitForExit();
EventLog.WriteEntry("Ended Nginx Service", EventLogEntryType.Information);
}
}
catch (Exception ex)
{
EventLog.WriteEntry(ex.Message, EventLogEntryType.Warning);
}
}
protected override void OnStop()
{
if (_xginxTimer != null)
{
_xginxTimer.Stop();
}
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
components = new Container();
base.ServiceName = "Service1";
}
}
}
Continue reading...
I have a service that just needs to start an executable and it starts in memory ok, the executable also runs in memory but the service just hangs with green progress bar and eventually times out with the service didn't respond in a timely fashion error. The service just gets stuck at starting after the error.
Here is the code for the service.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Threading.Tasks;
using System.Timers;
namespace T4CNginxService
{
public class Service1 : ServiceBase
{
private Timer _xginxTimer;
private Process[] serviceNginx = Process.GetProcessesByName("nginx");
private IContainer components = null;
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
Task task = Task.Run(delegate
{
_xginxTimer_Elapsed();
});
task.Wait();
}
public void _xginxTimer_Elapsed()
{
try
{
if (serviceNginx.Count() <= 0)
{
EventLog.WriteEntry("Started Nginx Service", EventLogEntryType.Information);
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.WorkingDirectory = "C:\\Program Files (x86)\\Lely\\T4C\\nginx";
Process process = new Process();
processStartInfo.FileName = "C:\\Program Files (x86)\\Lely\\T4C\\nginx\\nginx.exe";
process.StartInfo = processStartInfo;
process.StartInfo.Verb = "runas";
process.Start();
process.WaitForExit();
EventLog.WriteEntry("Ended Nginx Service", EventLogEntryType.Information);
}
}
catch (Exception ex)
{
EventLog.WriteEntry(ex.Message, EventLogEntryType.Warning);
}
}
protected override void OnStop()
{
if (_xginxTimer != null)
{
_xginxTimer.Stop();
}
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
components = new Container();
base.ServiceName = "Service1";
}
}
}
Continue reading...