Hi All,
I need to run my program in windows service, it possible?.I test a lot of code but fail in OnStart method.
somebody can show the simple code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace Win_SerV
{
public partial class TesT_Service : ServiceBase
{
public TesT_Service()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
try
{
using (System.Diagnostics.Process process = new System.Diagnostics.Process())
{
process.StartInfo = new System.Diagnostics.ProcessStartInfo(@"C:\\Users\\family\\Desktop\\_Exe_6.exe");
process.StartInfo.CreateNoWindow = true;
process.StartInfo.ErrorDialog = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.Start();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
protected override void OnStop()
{
}
}
}
