DispatcherTimer は、条件を追加するか、コンストラクターの外部でタイマーを開始しようとすると、コードを実行しません。
私が抱えている問題は、ボタン Show_ClickStuff がクリックされる前に、グラフィックスレイヤーが追加する条件なしでコンストラクターで DispatchTimer を開始した場合です。コンストラクターですべてを開始するのではなく、if 条件を Show_ClickStuff または _timer_tick に配置すると、コードにブレーク ポイントを配置して、タイマーがコード行にヒットするのを監視できますが、コード行は実行されません。条件を削除すると、コードが実行されます。私はあらゆる種類のバリエーションを試しましたが、これを必要な方法で機能させることはできません
System.Windows.Threading の使用; .NET Framework 4.5 コード ファイル: .xaml.cs Silverlight 4
public Tool()
{
InitializeComponent();
_timer1 = new DispatcherTimer();
//_timer1.Start();
_timer1.Interval = TimeSpan.FromMilliseconds(4000);
_timer1.Tick += new EventHandler(_timer_tick);
}
private void Show_ClickStuff(object sender, RoutedEventArgs e)
{
ToggleStuff();
if (showStuff.IsChecked == true)
{
//Timer_Toggle(this, null);
//_timer1 = new DispatcherTimer();
//_timer1.Start();
//_timer1.Interval = TimeSpan.FromMilliseconds(4000);
//_timer1.Tick += new EventHandler(_timer_tick);
_timer1.Start();
}
else if (!_timer1.IsEnabled && showStuff.IsChecked == true)
{
_timer1.Start();
}
else
{
_timer1.Stop();
}
}
private void _timer_tick(object sender, EventArgs e)
{
_map.Layers.Remove(_stuffLayer);
GetStuff();
_map.Layers.Add(_stuffLayer);
}