将Program类的删除,将里面的静态类Main修改后放入服务类中:
Server1 sv = new Server1();
if (args.Length > 0)
{
sv.OnStart(args);
char c;
while ((c = Convert.ToChar(Console.Read())) != 'q')
if (c == 'g') GC.Collect();
sv.OnStop();
Console.ReadLine();
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
sv
};
ServiceBase.Run(ServicesToRun);
}
}
protected override void OnStart(string[] args)
{
}
protected override void OnStop()
{
}
}
新闻热点
疑难解答