コード例 #1
0
 void backgroundWorkerTimeAgo_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     try
     {
         int nextUpdateInMilliSeconds = 60000;
         if (e.Result != null)
         {
             try
             {
                 backgroundWorkerTimeAgoResult result = e.Result as backgroundWorkerTimeAgoResult;
                 _humanReadableAgo = result.HumanReadableTimeAgo;
                 NotifyPropertyChanged("HumanReadableAgo");
                 nextUpdateInMilliSeconds = result.SecondsTillNextUpdate * 1000;
                 timerHumanReadableAgo    = new Timer(new TimerCallback(timerHumanReadableAgoUpdate), null, Math.Max(1000, nextUpdateInMilliSeconds), 0);
             }
             catch
             {
                 _humanReadableAgo = null;
             }
         }
         else
         {
             if (timerHumanReadableAgo != null)
             {
                 timerHumanReadableAgo.Dispose();
             }
             timerHumanReadableAgo = new Timer(new TimerCallback(timerHumanReadableAgoUpdate), null, Math.Max(1000, nextUpdateInMilliSeconds), 0);
         }
     }
     catch (Exception exp)
     {
         Console.WriteLine(exp.Message);
     }
 }
コード例 #2
0
 void backgroundWorkerTimeAgo_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     try
     {
         int nextUpdateInMilliSeconds = 60000;
         if (e.Result != null)
         {
             try
             {
                 backgroundWorkerTimeAgoResult result = e.Result as backgroundWorkerTimeAgoResult;
                 _humanReadableAgo = result.HumanReadableTimeAgo;
                 NotifyPropertyChanged("HumanReadableAgo");
                 if (result.StopUpdating)
                 {
                     return;
                 }
                 if (result.SecondsTillNextUpdate < 1)
                 {
                     result.SecondsTillNextUpdate = 120;
                 }
                 nextUpdateInMilliSeconds = result.SecondsTillNextUpdate * 1000;
                 if (result.SecondsTillNextUpdate < 5)
                 {
                     AppController.Current.Logger.writeToLogfile("Immediate refresh of HumanReadableAgo");
                 }
                 if (timerHumanReadableAgo != null)
                 {
                     timerHumanReadableAgo.Dispose();
                 }
                 timerHumanReadableAgo = new Timer(new TimerCallback(timerHumanReadableAgoUpdate), null, Math.Max(1000, nextUpdateInMilliSeconds), 0);
             }
             catch
             {
                 _humanReadableAgo = null;
             }
         }
         else
         {
             if (timerHumanReadableAgo != null)
             {
                 timerHumanReadableAgo.Dispose();
             }
             timerHumanReadableAgo = new Timer(new TimerCallback(timerHumanReadableAgoUpdate), null, Math.Max(1000, nextUpdateInMilliSeconds), 0);
         }
     }
     catch (Exception exp)
     {
         Console.WriteLine(exp.Message);
     }
 }