小编Xby*_*nce的帖子

任务完成后运行一个函数

我想异步运行一个函数来防止UI冻结.这里是按钮单击事件.

private void btnEncrypt_Click(object sender, EventArgs e)
{
    // Create new Vigenere object instant
    cryptor = new Vigenere(txtPassword.Text, txtBox.Text);

    // Run encryption async
    Task<string> T = new Task<string>(cryptor.Encrypt);
    T.Start();
}
Run Code Online (Sandbox Code Playgroud)

现在我希望在Task T完成时调用以下函数,并将其返回值作为参数,如下所示:

private void Callback(string return_value)
{
    txtBox.Text = return_value

    // Some other stuff here
}
Run Code Online (Sandbox Code Playgroud)

怎么做到这一点?

c# multithreading asynchronous callback asynccallback

2
推荐指数
2
解决办法
7191
查看次数