我有一个C++ MFC应用程序(MGen),它显示在Windows10上启动和显示图形用户界面之间的10-20秒暂停。我使用MSVS2017性能分析器(CPU使用)来查找在发布构建过程中占用MSVS2017时间的函数。此暂停位于ProcessShellCommand
run中,特别是在CMFCRibbonBar::RecalcLayout
、CMFCRibbonBar::LoadFromResource
、CDockingManager::EnableAutoHidePanes
中。
当某些程序关闭时,暂停似乎被删除或减少。首先,我注意到关闭,固定暂停,并再次启动它,返回暂停。然后我发现,即使没有任务管理器,暂停也可能发生。关闭Chrome有助于将暂停时间减少到2-3秒。
我还发现,如果由MSVS2017中的MFC创建的空项目也存在此问题。
我试过:
代码可以在GitHub上找到
BOOL CMGenApp::InitInstance()
{
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinAppEx::InitInstance();
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
EnableTaskbarInteraction(FALSE);
// Initialize GDI+
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
SetRegistryKey(_T("MGen"));
LoadStdProfileSettings(10); // Load standard INI file options (including MRU)
InitContextMenuManager();
InitKeyboardManager();
InitTooltipManager();
CMFCToolTipInfo ttParams;
ttParams.m_bVislManagerTheme = TRUE;
theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMGenDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CMGenView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
// Enable DDE Execute open
EnableShellOpen();
// Dispatch commands specified on the command line. Will return FALSE if
// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
// call DragAcceptFiles only if there's a suffix
// In an SDI app, this should occur after ProcessShellCommand
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
return TRUE;
}
我在两台PC上都使用最新的组件(英特尔I7-8700K有64 Gb RAM,英特尔i7-4770 K有32 Gb RAM,SSD),而且没有性能问题。在应用程序启动暂停期间,应用程序只使用CPU。
详细的性能分析器结果:
更详细的分析:
此外,ExitInstance中也存在同样的问题:
发布于 2018-11-15 18:10:29
这个问题在微软是一个已知的问题。它是用Windows update修复的。因此,要修复Windows 10,需要更新Windows 10。
https://stackoverflow.com/questions/49362503
复制相似问题