Brad Fitzpatrick (brad) wrote,
Brad Fitzpatrick

catching exceptions from C# async method calls

In C#, callers can invoke any method as async, without the method implementation being aware of it. Classes can also choose to implement explicit async interfaces, and most the .NET framework does for the common stuff.

So that's pretty cool.

But here's my latest problem: if a method throws an exception while operating async (in another thread), how do I catch it? It's not even my method implementation.

My load balancer is kicking ass now.... I was testing it with multiple clients, all fetching at different slow speeds, and verifying it sucks down the page from the backend, holding it in memory.

But if I kill a client while downloading, the async IO to write to that client fails (socket goes away), and the worker thread throws an exception. The program stays alive but I'm not sure what's catching it... it writes the exception to the console, which isn't a good solution. I also want to catch it to explicitly shutdown/close/dispose of the socket, and not wait for the GC to do it.

I wonder if there's any difference in behavior between Windows and Mono. I might need to get vmware working again.

  • Happy Birthday!

    Happy 20th Birthday, LiveJournal! 🐐🎂🎉

  • hi

    Posting from the iPhone app. Maybe I'm unblocked now.

  • Why, hello...

    Long time no see. How's my baby doing?

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.