AsyncResult in .net 6.0

414 Views Asked by At

After some research, I found out that Microsoft doesn't support System.Runtime.Remoting.Messaging from .net core onwards.

I have the following code that makes use of the library:

   Delegate Sub LogExceptionDelegate(ByVal e As Exception)
   Public Sub HandleException(ByVal e As Exception)
      Dim logDelegate As New LogExceptionDelegate(AddressOf LogException)
      logDelegate.BeginInvoke(e, New AsyncCallback(AddressOf LogCallBack), Nothing)
   End Sub
   Private Sub LogCallBack(ByVal result As IAsyncResult)
      Dim asyncResult As AsyncResult = CType(result, AsyncResult)
      Dim logDelegate As LogExceptionDelegate = CType(asyncResult.AsyncDelegate, LogExceptionDelegate)
      If Not asyncResult.EndInvokeCalled Then
         logDelegate.EndInvoke(result)
      End If
   End Sub

Would the following be a good replacement in .net6?

   Delegate Sub LogExceptionDelegate(ByVal e As Exception)
   Public Sub HandleException(ByVal e As Exception)
      Dim logDelegate As New LogExceptionDelegate(AddressOf LogException)
      Task.Run(Sub() logDelegate.Invoke(e))
   End Sub

Any help is appreciated.

0

There are 0 best solutions below