码迷,mamicode.com
首页 > Windows程序 > 详细

windows 服务

时间:2015-03-11 01:55:55      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
 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.htmhttp://jingyan.baidu.com/article/fa4125acb71a8628ac709226.html

windows 服务

标签:

原文地址:http://www.cnblogs.com/yuanjiehot/p/4328871.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!