Question:
I have to call a method on .NET object which is defined as
IAsyncResult BeginListMetrics( ListMetricsRequest listMetricsRequest,
AsyncCallback callback, Object state )
Is it possible to use a powershell function as a AsyncCallback delegate? How?
Answer:
Scriptblocks can be converted into most types of delegates by casting as follows.
1 2 3 4 5 6 7 8 |
$myCallback = [AsyncCallback]{ param( $asyncResult) # callback code if ($asyncResult.isCompleted) { get-date } } |