c# - 如何在 C# 中的静态类中创建一个简单的回调

标签 c# callback portable-class-library static-classes

我有一个静态类,它有一个方法再次调用另外两个静态类方法

基本上在第一个静态类中,我想知道一旦操作在其他两个静态类中完成

 public static class FirstClass{

    public static async System.Threading.Tasks.Task FirstClassMethod() 
        {
            SecondClass. SecondClassMethod();
            ThirdClass. ThirdClassMethod();
        }
 }

 public static class SecondClass{

    public static async System.Threading.Tasks.Task SecondClassMethod() 
        {

        }
 }

 public static class ThirdClass{

    public static async System.Threading.Tasks.Task ThirdClassMethod() 
        {

        }
 }

如果能帮助解决我的问题,我们将不胜感激

最佳答案

使用 Task.WhenAll,您可以创建一个包装多个任务并在所有包装任务完成时完成的单个任务。

 public static class FirstClass{

    public static async System.Threading.Tasks.Task FirstClassMethod() 
        {
            return await Task.WhenAll(
                SecondClass.SecondClassMethod(),
                ThirdClass.ThirdClassMethod()
            );
        }
 }

 public static class SecondClass{

    public static async System.Threading.Tasks.Task SecondClassMethod() 
        {

        }
 }

 public static class ThirdClass{

    public static async System.Threading.Tasks.Task ThirdClassMethod() 
        {

        }
 }

关于c# - 如何在 C# 中的静态类中创建一个简单的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44421722/

相关文章:

mono - 寻找用于跨平台开发的最佳 PCL 配置文件

c# - 为什么在 VB.NET 中可以将 Nothing 赋值给 Integer?

c# - 将传统事件添加到自定义控件

javascript - 在 async forEach 循环下通过 async 方法修改数组对象

android - herenow() successCallback 返回channel=null

sqlite 不适合 PCL 开发?

c# - 在 C# 中从字符串创建匿名方法

javascript - MVC 中如何在两个模型之间共享对象?

android - 如何从第二个子 fragment 回调到原始父 fragment ?

xamarin.ios - 可移植类库 System.Object 错误