向BeginInvoke()传递多个参数

本文关键字:参数 BeginInvoke | 更新日期: 2023-09-27 18:08:25

我有简单的逻辑。

public static void NotifyAboutNewJob(int jobId, bool forceSending = false)
{
        Action<int> notifier = SendAppleNotifications;
        notifier.BeginInvoke(jobId, null, null);
}

方法sendapplenotifations有一个参数,很容易传递给BeginInvoke。现在我添加了第二个参数forceSending。问题是,我不知道如何将其传递到BeginInvoke

我应该把它作为第三个参数传递给object吗?

private static void SendAppleNotifications(int jobId, bool forceSending = false){...}

或者答案是:

Action<int, bool> notifier = SendAppleNotifications;
notifier.BeginInvoke(jobId, forceSending, null, null);

向BeginInvoke()传递多个参数

Action<int>更改为Action<int, bool>

Action<int, bool> notifier = SendAppleNotifications;
notifier.BeginInvoke(jobId, forceSending, null, null); // You can now pass true or false as 2nd parameter.