• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

无限循环出猎

  • 博客园
  • 订阅
  • 管理

公告

View Post

创建一个服务类MyClass,里面包含两个方法Start和Stop

安装,卸载 Cmd命令  installutil      WindowsService_test.exe  (安装Windows服务)  installutil /u   WindowsService_test.exe  (卸载Windows服务)   代码下载:https://files.cnblogs.com/aierong/WindowsService_test.rar       b.利用组件Topshelf   本方式特点:代码简单,开源组件,Windows服务可运行多个实例   Topshelf是一个开源的跨平台的服务框架,支持Windows和Mono,只需要几行代码就可以构建一个很方便使用的服务. 官方网站:http://topshelf-project.com       第1步:引用程序集TopShelf.dll和log4net.dll   第2步:创建一个服务类MyClass,里面包含两个方法Start和Stop,还包含一个定时器Timer,每隔5秒往文本文件中写入字符 。更多内容http://zhieyuoa.blog.chinaunix.net 

       public class MyClass     {         readonly Timer _timer;

        private static readonly string FileName = Directory.GetCurrentDirectory ( ) + @"\" + "test.txt";

        public MyClass ( )         {             _timer = new Timer ( 5000 )            

{                 AutoReset = true ,                 Enabled = true             };

            _timer.Elapsed += delegate ( object sender , ElapsedEventArgs e )            

{                 this.witre ( string.Format ( "Run DateTime {0}" , DateTime.Now ) );             };         }

        void witre ( string context )         {             StreamWriter sw = File.AppendText ( FileName );            

sw.WriteLine ( context );             sw.Flush ( );             sw.Close ( );         }

        public void Start ( )         {             this.witre ( string.Format ( "Start DateTime {0}" , DateTime.Now ) );         }

        public void Stop ( )         {             this.witre ( string.Format ( "Stop DateTime {0}" , DateTime.Now ) + Environment.NewLine );         }

    } 健康知识微创保胆取石手术   

posted on 2012-06-04 11:23  无限循环出猎  阅读(164)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3