zoukankan      html  css  js  c++  java
  • 通过.NET平台编写和发布简单的Windows Service

    新建一个(VB.NET/C#)项目,选择Windows Service应用..然后在OnStart类里就可以添加代码了.
      如果想实现定时运行,活实时监听的功能,可以用.NET 提供的TIMER类.
      以下是代码片段.
       private void theTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
      {

      if (!ExCondition())

      { return;

      }

      try

      {

      theTimer.Enabled = false;

      MyTransaction();

      }

      catch(Exception es)

      {

      WriteLog(es.Message);

      }

      theTimer.Enabled = true;

      }

      //检测执行条件

      private bool ExCondition()

      {

      DateTime dtNow = DateTime.Now;

      if(this.currentmode.Equals("auto"))

      {

      string[] frev = this.freqvalue.Split('-');

      switch( this.freq)

      {

      case "2"://2-每小时

      if( (dtNow.Minute == 59)&(dtNow.Second< 30))

      {

      return true;

      }

      break;

      case "4"://4-每天,

      if((dtNow.Hour == int.Parse(frev[1]))&(dtNow.Minute == int.Parse(frev[2]))&(dtNow.Second<30))

      {

      return true;

      }

      break;

      case "8"://8-每周,

      int we = int.Parse(frev[0].Substring(1,1));

      if((dtNow.DayOfWeek.ToString().Equals(Week[we]))&(dtNow.Hour == int.Parse(frev[1]))&(dtNow.Minute == int.Parse(frev[2]))&(dtNow.Second<30))

      {

      return true;

      }

      break;

      case "16"://16-每月,

      int mm = int.Parse(frev[0].Substring(1,frev[0].Length-1));

      if((dtNow.Day == mm)&(dtNow.Hour == int.Parse(frev[1]))&(dtNow.Minute == int.Parse(frev[2]))&(dtNow.Second<30))

      {

      return true;

      }

      break;

      default://无触发

      return true;

      break;
      }

      }

      else

      {

      switch(this.startpoint)

      {

      case "0":

      return true;

      break;

      default:

      string[] st = startpoint.Split('-');

      if((dtNow.Hour == int.Parse(st[0]))&(dtNow.Minute ==int.Parse(st[1]))&(dtNow.Second<30))

      {

      return true;

      }

      break;

      }

      }

      return false;

      }

      注册你的Windows Service程序.

      用InstallUtil IASserver.exe (这个文件默认在C:\WINNT\Microsoft.NET\Framework\v1.1.4322下)

      InstallUtil IASserver.exe

      InstallUtil IASserver.exe /u (卸载)

  • 相关阅读:
    zoj 2316 Matrix Multiplication 解题报告
    BestCoder7 1001 Little Pony and Permutation(hdu 4985) 解题报告
    codeforces 463C. Gargari and Bishops 解题报告
    codeforces 463B Caisa and Pylons 解题报告
    codeforces 463A Caisa and Sugar 解题报告
    CSS3新的字体尺寸单位rem
    CSS中文字体对照表
    引用外部CSS的link和import方式的分析与比较
    CSS样式表引用方式
    10个CSS简写/优化技巧
  • 原文地址:https://www.cnblogs.com/VinC/p/1991089.html
Copyright © 2011-2022 走看看