c# - 如何逐行执行代码?

Ash*_*nko 0 c# process

以此示例代码为例

private void test()
{
    Label1.Text = "Function 1 started.";
    function1(); //This function takes a while to execute say 15 seconds.
    Label2.Text = "Function 1 finished.";
}
Run Code Online (Sandbox Code Playgroud)

如果运行此操作,您将永远不会看到功能1启动.所以我的问题是,是否有任何c#函数可以调用show更改标签.像这样的东西

private void test()
{
    Label1.Text = "Function 1 started.";
    this.DoProcess();       //Or something like this.
    function1();             
    Label2.Text = "Function 1 finished.";
}
Run Code Online (Sandbox Code Playgroud)

我知道这可以使用线程完成,但是想知道是否还有其他方法.

谢谢你.

Yur*_*ich 6

Application.DoEvents()