I have a WPF application and I'm trying to do some async stuff in the startup. I'm trying to move from:
[STAThread]
public static void Main(string[] args)
{
_app = new Application
{
ShutdownMode = ShutdownMode.OnExplicitShutdown
};
_app.Exit += AppOnExit;
_app.DispatcherUnhandledException += BoomAd;
SyncInitialization();
_app.Run(new MainWindow(startupFiles));
}
To
[STAThread]
public static async Task Main(string[] args)
{
_app = new Application
{
ShutdownMode = ShutdownMode.OnExplicitShutdown
};
_app.Exit += AppOnExit;
_app.DispatcherUnhandledException += BoomAd;
await InitializeAsync().ConfigureAwait(true);
_app.Run(new MainWindow(startupFiles));
}
However, one of my initialization pieces stores the UI dispatcher for use later, and it validates that the dispatcher that it gets is STA. When I have the first code (void Main) it works fine, but when I have the second code (async Task Main) the dispatcher it gets is MTA. I have also looked in debugger and _app.Dispatcher.Thread is an MTA thread...
So what am I doing wrong that it's MTA? How do I get this type of startup correct?