1、创建服务项目,会生成一个程序文件如 myService.cs C# -> 经典桌面 -> windows服务2、创建主程序(例如定时服务)protectedoverridevoidOnStart(string[]args){vartimer=newSystem.Timers.Timer();timer.Interval=1000*30;timer.Elapsed+=StartService;timer.Enabled=true;}privatevoidStartService(objectsender,System.Timers.ElapsedEventArgse){using(StreamWriterw=newStreamWriter(newFileStream(@"f:\a.txt",FileMode.Append,FileAccess.Write,FileShare.ReadWrite),Encoding.UTF8)){w.Write(DateTime.Now.ToString()+"\r\n");w.Close();w.D