Passing an *Awaitable* Anonymous Function as a Parameter

后端 未结 2 1360
Happy的楠姐
Happy的楠姐 2021-01-07 16:30

Code first. This is what I\'m trying to do. I\'m close, but I think I just need to fix the way I\'ve defined my parameter in the UpdateButton method.

private         


        
2条回答
  •  猫巷女王i
    2021-01-07 16:56

    private async void UpdateButton(Func> post)
    {
        if (!await post())
            ErrorBox.Text = "Error posting message.";
    }
    

    --EDIT--

    UpdateButton(()=>Post("ss"));
    
    private async void UpdateButton(Func> post)
    {
        if (!await post())
            this.Text = "Error posting message.";
    }
    
    public virtual async Task Post(string messageId)
    {
        return await Task.Factory.StartNew(() => true);
    }
    

提交回复
热议问题