Pass multiple parameters to BeginInvoke()
Asked Answered
R

1

7

I have simple (as i think) logic.

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

Method SendAppleNotifications had one parametera and it was easy to pass it into BeginInvoke. Now i have added second parameter forceSending. And problem - i don't know how to pass it into BeginInvoke.

Should i pass it as 3rd param as object ?

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

Or this is the answer :

Action<int, bool> notifier = SendAppleNotifications;
notifier.BeginInvoke(jobId, forceSending, null, null);
Rust answered 17/8, 2015 at 15:16 Comment(1)
You could also implement it like this: Task.Run(() => SendAppleNotifications(jobId, forceSending));Torpedo
C
8

Change your Action<int> to Action<int, bool>

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

then it should work ok.

Coherent answered 17/8, 2015 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.