Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Async Delegate in .NET Core Class

$
0
0

Hi,

I have a delegate for reporting errors, I'm porting it from a .NET Framework Class and it's the only thing remaining to fix.

This is where the invoke is happening async:

        /// <summary>
        /// Reports an error that happened in a threading environment
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="ex">The exception that happened</param>
        /// <returns>True if the error could be passed on; false otherwise</returns>
        public static bool ReportError(object sender, Exception ex)
        {
            var SevereErrorHappenedEvent = SevereErrorHappened;
            if (SevereErrorHappenedEvent == null) return false;
            else
            {
                SevereErrorHappenedEvent.BeginInvoke(sender, ex, (a) =>
                {
                    var ar = a as AsyncResult;
                    var invokedMethod = ar.AsyncDelegate as GeneralExceptionHandler;
                    invokedMethod.EndInvoke(a);
                }, null);
                return true;
            }
        }

The ServerErrorHappened typed as:

public static event GeneralExceptionHandler SevereErrorHappened;

And the declaration:

    /// <summary>
    /// A delegate to inform of exceptions
    /// </summary>
    /// <param name="sender">The sender of this event</param>
    /// <param name="ex">The exception</param>
    public delegate void GeneralExceptionHandler(object sender, Exception ex);

What is the equivalent for .NET Core?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>