首页 > 学院 > 开发设计 > 正文

windows服务

2019-11-14 16:08:14
字体:
来源:转载
供稿:网友
 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             try48             {49 50                 CreateTeam();51                 CreatePerson();52                 UploadAllDir();53             }54             catch55             {56             }57             finally58             {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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表