2

我有一个方法。

public bool bBIntersectsBT(Rect barTopTipRect, Rect barBottomTipRect, Rect blueBallRect)
    {
        barTopTipRect.Intersect(blueBallRect);
        barBottomTipRect.Intersect(blueBallRect);

        if (barTopTipRect.IsEmpty && barBottomTipRect.IsEmpty)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

我想在再次执行此方法之前将此方法延迟 2 秒。我已经阅读了有关 Thread.Sleep 的信息,但是,这不是我想要的。我不希望程序暂停并恢复它。

4

2 回答 2

2

使用DispatcherTimer

DispatcherTimer timer = new DispatcherTimer();

//TimeSpan is in format: Days, hours, minutes, seconds, milliseconds.
timer.Interval = new TimeSpan(0, 0, 0, 2);
timer.Tick += timerTick;
timer.Start();

private void timerTick(Object sender, EventArgs e)
{
    //Your code you want to execute every 2 seconds

    //If you want to stop after the two seconds just add timer.Stop() here
}
于 2013-08-14T12:16:03.277 回答
1

您可以使用Dispatch Timer来实现您的目标。需要时将其设置为 2 秒。在你完成它之后。你可以阻止它。

于 2013-08-14T09:08:12.200 回答