我用Thread.Sleep(5000)的方法每隔多长时间执行一个既定的动作。
  每次执行了几次后就不执行了(次数也不确定的)。要重新启动项目进程后才可以

解决方案 »

  1.   

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemThreadingThreadClassSleepTopic1.asp
      

  2.   

    Parameters
    millisecondsTimeout 
    The number of milliseconds for which the thread is blocked. Specify zero (0) to indicate that this thread should be suspended to allow other waiting threads to execute. Specify Infinite to block the thread indefinitely.毫秒应该是5秒
      

  3.   

    Thread.Sleep(int x)使线程阻塞x毫秒。只有当该线程是被其他的线程通过调用Thread.Interrupt()或者Thread.Abort()方法,才能被唤醒。如果对处于阻塞状态的线程调用Thread.Interrupt()方法将使线程状态改变,但是会抛出ThreadInterupptedException异常,你可以捕获这个异常并且做出处理,也可以忽略这个异常而让运行时终止线程。在一定的等待时间之内,Thread.Interrupt()和Thread.Abort()都可以立即唤醒一个线程。