在 C#中 怎么样让 :当程序的一个函数运行的时间超过预先设定的时间时就自动结束这个函数的运行?

解决方案 »

  1.   

    写个Timer 监视函数执行时间,如果超过指定时间抛出异常。
    没有试过,你可以试试。
      

  2.   

    没做过,用backgroundworker组件貌似可以实现你的要求
    backgroundworker组件绑定这个函数
    start的时候启动一个timer组件
    在timer的tick事件里取消backgroundworker运行
      

  3.   

    void f(int tickcount)
    {
       int i = GetTickCount();
       while((GetTickCount() - i) < tickCount)
       {
           DoSomeThing();
       }
    }