-3

无论如何你可以从这样的另一个方法中退出一个方法吗?

            if (workisdone())
            Xceed.Wpf.Toolkit.MessageBox.Show("Done");
            return.workisdone(); // or something like that?????
            DispatcherTimer timer = (DispatcherTimer)sender;
            timer.Stop();
            timer = null;
        }
    }
4

4 回答 4

3
if (workisdone())
{
    Xceed.Wpf.Toolkit.MessageBox.Show("Done");
    return;
}
DispatcherTimer timer = (DispatcherTimer)sender;
timer.Stop();
timer = null;
于 2013-04-18T14:14:01.933 回答
2

除非您在某处发生了一些多线程,否则您实际上无法进入 if 块,直到您已经退出该workisdone()方法...

于 2013-04-18T14:14:13.490 回答
1
    bool res = workisdone();
    if(res)
       return res;
   //rest of code here - any code below here will not run if workisdone() returns true

我通常会假设您在退出循环之前停止计时器,但这段代码看起来像您想要的。

于 2013-04-18T14:18:49.267 回答
0

好的,我明白你在做什么。因此,以这种方式修改您的代码:

var isWorkDone = workisdone();

// i think, you should stop the timer no matter what the workisdone() result is.
DispatcherTimer timer = (DispatcherTimer)sender;
timer.Stop();
timer = null;

// pop the msg only if workisdone() == true
if (isWorkDone)
{
  Xceed.Wpf.Toolkit.MessageBox.Show("Done");
}

return isWorkDone; // will return pass or fail.
于 2013-04-18T14:23:02.563 回答