Open
Description
Background and motivation
I have a complex winform application and made multiple forms run message loops on independent threads, I registered ThreadException on each form's thread, and hope to get current form thread's application context in ThreadException event callback, to show a dialog with current application context's MainForm as dialog's owner (ensure alert shows in front of current thread's main form).
API Proposal
namespace System.Windows.Forms;
public sealed partial class Application
{
public static ApplicationContext GetCurrentApplicationContext()
=> ThreadContext.FromCurrent().ApplicationContext;
}
API Usage
var owner = Application.GetCurrentApplicationContext().MainForm;
Alternative Designs
No response
Risks
Add a new method, no clearly risk.
Will this feature affect UI controls?
No;
No;
No;