This app statically links multiple mfc dlls and loads those at app startup. But in some cases when CPU usage is high it crashes while activating the frame window. This crash due to AfxGetThread returning NULL in mfc140!CFrameWnd::OnActivateTopLevel at app startup. It has only crashed in client domains and while debugging through time travel debugger in local system. Client domain crash has mostly happened while user was starting a new session in morning. So there may have been some load.
The apps main window is part of a mymain.dll. I added some logs to the mymain dll's app object ctor to log threadid. When I run the app normally on my system it calls the app object ctor on the same thread that calls mfc140!CFrameWnd::OnActivateTopLevel and does not crash. But when I run the app through time travel debugger it calls the app object ctor on another thread that is not the main thread and later crashes on main thread in CFrameWnd::OnActivateTopLevel
00 MyMain!CMyMainApp::CMyMainApp
01 MyMain!`dynamic initializer for 'theApp''
02 ucrtbase!initterm
03 MyMain!dllmain_crt_process_attach
04 MyMain!dllmain_dispatch
05 mscoreei!CorDllMain
06 mscoree!_CorDllMain_Exported
07 ntdll!LdrpCallInitRoutine
08 ntdll!LdrpInitializeNode
09 ntdll!LdrpInitializeGraphRecurse
10 ntdll!LdrpInitializeGraphRecurse
11 ntdll!LdrpInitializeProcess
12 ntdll!LdrpInitialize
13 ntdll!LdrInitializeThunk
Please help understand why the loader is loading this mfc dll on a background thread on certain conditions?