Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AsyncCallback in Powershell

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?

like image 765
TOP KEK Avatar asked Dec 27 '22 04:12

TOP KEK


1 Answers

Scriptblocks can be converted into most types of delegates by casting as follows.

$myCallback = [AsyncCallback]{
  param( $asyncResult)
  # callback code
  if ($asyncResult.isCompleted) {
    get-date
  }
}
like image 131
Χpẘ Avatar answered Dec 28 '22 23:12

Χpẘ