1

ここでは、現在のウィンドウサービスソリューションで使用している貼り付けたコードを以下に示します。これは毎日午前10時にジョブを実行し、App.configuarationファイルを使用してパラメーターを渡します。

APP.CONFIG

<add key ="FIREHOST_TIME" value ="10" ></add>
<add key ="SETDAYS" value ="1" ></add>

ページの後ろのコード

protected override void OnStart(string[] args)
{

     DateTime tenAM = DateTime.Today.AddHours(FIREHOST_TIME);



      if (DateTime.Now > tenAM)
          tenAM = tenAM.AddDays(SETDAYS);


      // calculate milliseconds until the next 10:00 AM.  
      int timeToFirstExecution = (int)tenAM.Subtract(DateTime.Now).TotalMilliseconds;

      // calculate the number of milliseconds in 24 hours.   
      int timeBetweenCalls = (int)new TimeSpan(24, 0, 0).TotalMilliseconds;

      TimerCallback methodToExecute = kickstart;

      // start the timer.  The timer will execute "ProcessFile" when the number of seconds between now and   
      // the next 10:00 AM elapse.  After that, it will execute every 24 hours.   
      System.Threading.Timer timer = new System.Threading.Timer(methodToExecute, null, timeToFirstExecution, timeBetweenCalls);


}

現在、以下の条件に基づいて、サービスを実行しようとしています。

サービスを開始したいのですが、app.configに新しく追加するこの新しいタグに基づいてジョブを実行する必要があります

BY based on above four tags

if RUN_NOW == 1

    has to perform service based on FIREHOST_TIME and SETDAYS normal thing

else 

    service have to perform the Job doing by after 5 days(because WAIT_DAYS = 5) 
    then it have to use the FIREHOST_TIME and SETDAYS value

注:サービスは停止しないでください。開始状態のみである必要があります

どうすればこれを達成できますか?

4

1 に答える 1

1

プログラムロジック全体をどのように実装したいか正確にはわかりません。サービスを再起動せずに構成ファイルの変更に対応する方法について説明します。これは次の方法で実行できます。

ConfigurationManager.RefreshSection("thesectiontorefresh"); 

より良い作業のために、誰かがapp.configファイルを変更するのをリッスンしているFileSystemWatcherでこれを呼び出し、上記のように更新を呼び出した後に適切に反応することができます。これにより、構成ファイルのパスを取得できます。

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

一般的な情報として、独自のサービスを作成する代わりに、システムのスケジュールされたタスクを使用して問題を解決する方法を再設計することを検討してください。

于 2012-07-25T15:40:12.097 に答える