在C#中的特定时间之前执行操作

时间:2014-06-16 19:12:22

标签: c# time nxt

我正在尝试开发运行电机的Windows Phone应用程序。我想仅执行MoveCar方法1秒钟,然后Stop

我有这个代码可以正常移动C电机:

CarControl _cc;    
private void UP_Motor_C(object sender, RoutedEventArgs e)
    {
        _cc.Turn = 50; //the C motor will start running in 50% speed
        _cc.LeftSpeed = 0; //the B motor will stop working
        _cc.RightSpeed = 0; //the A motor will stop working

        _cc.MoveCar();
    }

我的问题是我错过了一段代码才能启动MoveCar一秒钟。什么是实现我想要的最佳方式?

1 个答案:

答案 0 :(得分:1)

    _cc.Turn = 50; //the C motor will start running in 50% speed

    _cc.LeftSpeed = 0; //the B motor will stop working
    _cc.RightSpeed = 0; //the A motor will stop working

    _cc.MoveCar();

    System.Threading.Thread.Current.Sleep(1000);