将Program类的删除,将里面的静态类Main修改后放入服务类中:
复制代码 代码如下:
partial class Server1 : Servicebase
{
public Server1()
{
InitializeComponent();
}
///
/// 应用程序的主入口点。
///
static void Main(string[] args)
{
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()
{
}
}



