dotnet / dotnet/dotnet-api-docs

ThreadException notice confusing

Open
#3,603 2 comments 0 reactions 0 assignees View on GitHub
area-WinForms Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

https://docs.microsoft.com/en-gb/dotnet/api/system.windows.forms.application.threadexception?view=netframework-4.7

On the `Application.ThreadException` page - there is the below notice:

> Caution
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.

That confused me - surely the event will be disposed when the application ends anyway? Or is this suggesting that some resources may be kept hold of, once my application has already terminated?

I looked at the code example on that page, which seems to do no special handling regarding this notice. I then Googled it - and seems I wasn't the only person confused:
https://stackoverflow.com/q/7812627/1768779
https://www.pcreview.co.uk/threads/detach-application-threadexception-event-really.3084009/

Is the explanation on StackOverflow correct? If so - that seems a niche case to pull out in a big red **Caution** box - could the situation be clarified?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.