1 public partial class Service1 : ServiceBase 2 { 3 4 public Service1() 5 { 6 InitializeComponent(); 7 } 8 9 protected override void OnStop() 10 { 11 //服务结束执行代码 12 } 13 protected override void OnPause() 14 { 15 //服务暂停执行代码 16 base.OnPause(); 17 } 18 protected override void OnContinue() 19 { 20 //服务恢复执行代码 21 base.OnContinue(); 22 } 23 protected override void OnShutdown() 24 { 25 //系统即将关闭执行代码 26 base.OnShutdown(); 27 } 28 29 30 31 protected override void OnStart(string[] args) 32 { 33 System.Timers.Timer timer = new System.Timers.Timer(10000000); //间隔10秒 34 timer.AutoReset = true; 35 timer.Enabled = false; //执行一次 36 timer.Elapsed += new ElapsedEventHandler(WriteSomething); 37 timer.Start(); 38 } 39 40 41 42 43 44 private void WriteSomething(object source, System.Timers.ElapsedEventArgs e) 45 { 46 47 try 48 { 49 50 CreateTeam(); 51 CreatePerson(); 52 UploadAllDir(); 53 } 54 catch 55 { 56 } 57 finally 58 { 59 60 } 61 } 62 63 64 public void CreatePerson() 65 { 66 67 } 68 69 70 71 public void CreateTeam() 72 { 73 74 } 75 76 77 public void UploadAllDir() 78 { 79 80 } 81 82 83 }View Code
感谢百度经验分享者:文章转自http://jingyan.baidu.com/article/ea24bc395e16f8da62b331e7.htm及http://jingyan.baidu.com/article/fa4125acb71a8628ac709226.html