c# - 如何在不等待 C# 中被调用函数完成的情况下继续执行函数

标签 c# wpf

我的代码中有一个调度程序函数,它在某个特定时间调用另一个函数,如下所示:-

private void timer_startTimer_Tick(object sender, EventArgs e)
    {
        Target10 currentTime = this;
        currentTime.CurrentTime = currentTime.CurrentTime - 1;
        this.txttimer.Text = string.Concat("0 : ", Convert.ToString(this.CurrentTime));
        if(CurrentTime == 0)
            timer_startTimer.Stop();
        if (CuurentTime == 10)
        {
            getResult();
        }

    }

如上代码所述,我的函数 timer_startTimer_Tick 将在 10 秒时调用函数 getResult。函数 getResult() 需要一些时间才能完成。如何在不等待 getResult 函数完成的情况下继续我的父函数 timer_startTimer_Tick

最佳答案

将方法调用包装在任务中。

Task.Run(() => getResult());

关于c# - 如何在不等待 C# 中被调用函数完成的情况下继续执行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29216883/

相关文章:

.net - 更改列表框项目的 WPF 数据模板(如果选择)

.net - WPF 应用程序错误和 .Net Framework 修复

c# - HTTPContext 在 ASP.NET 和 iis express 中找不到客户端 CAC 证书

c# - 通过 ClosedXML.dll 打开 Excel 文件显示错误 "Excel found unreadable content"

c# - 将 C 字符串返回到 C# 程序

c# - Silverlight 作为桌面应用程序?

c# - 打开现有文件,追加一行

c# - 更改 Entity Framework 生成的中间表的表模式

.net - 在 WPF 中更改当前文化后,即时强制更新 UI

c++ - 通过 ActiveX 在 WPF 中使用 OpenGL?