0

私はこの関数を1秒ごとにタイマー時間を更新するように作成しました。

DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = TimeSpan.FromSeconds(1.0);

private void dispatcherTimer_Tick(object sender, EventArgs e)
{
            ApplicationVariables.ServerDateTime = CurrentDT = CurrentDT.AddSeconds(1);     
}

しかし、アプリケーションがしばらくハングした場合は、その時点でアプリケーションタイマーが停止し、アプリケーションタイマーの開始と開始に応答した後、実際の時間を表示するためにアプリケーションのハング時間を前回に追加するのではなく、前回から開始します。アプリケーションがハングした場合でもタイマーをオンにしておく方法を教えてください。

アプリケーションのハング状態を維持するためにBackgroundWorkerオブジェクトを使用しています。

通常、アプリケーションが富士通リーダーのオブジェクトを初期化しようとするとハングします。

詳細については、添付ファイルをご覧ください。

ここに画像の説明を入力してください

4

1 に答える 1

0

非ディスパッチャ タイマーを使用してタスクを実行し、必要に応じて呼び出して UI を更新することをお勧めします。

public System.Threading.Timer MyTimer { get; set; }

this.MyTimer = new System.Threading.Timer(new TimerCallback(MyTimer_CallBack), null, 1000, 1000);

void MyTimer_CallBack(object State)
{
this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (System.Threading.ThreadStart)delegate()
{
  ApplicationVariables.ServerDateTime = CurrentDT = CurrentDT.AddSeconds(1); 
});
}
于 2012-12-10T15:03:41.283 に答える