I have created a Visual Studio 2019 app, with OutputPanes, one is used for viewing Traces Logs from the WorkerThread.
In the WorkerThread, I fill a CStringList mStrDebugList
if somewhat useful has happened, and inform the Main UI with PostMessage
to read & show now.
//////////////////////////////////////////////////////////////////////////
// TRACE Debug messsages for this App wide
void TRACE_DEBUG(LPCTSTR pszstring)
{
TRACE(pszstring);
CTestApp* pApp = (CTestApp*)AfxGetApp();
if (pApp)
{
TAutoLock lock(res);
theApp.mStrDebugList.AddTail(pszstring);
}
This works, but if the App is minimized or not in the foreground, after hours the CStringList
contains too many elements (> 20k) and the Main UI is unresponsive (~5Min) until all elements are read & removed in the UI.
void COutputWnd::FillInfoWindow()
{
TestApp* pApp = (CTestApp*)AfxGetApp();
if (pApp)
{
TAutoLock lock(res);
CString str;
while (!theApp.mStrDebugList.IsEmpty ())
{
str.Format(_T("%5d %s"),nCounter, theApp.mStrDebugList.GetHead ());
m_wndOutputDebug.AddString (str);
theApp.mStrDebugList.RemoveHead ();
}
// Scroll to the end of Listbox
int nCount = m_wndOutputDebug.GetCount();
m_wndOutputDebug.SetTopIndex(nCount-1);
}
}
My question is, how can I check inside the WorkerThread if the UI is not active (dormant), to prevent filling the CStringList
with too many elements?
question from:
https://stackoverflow.com/questions/65830130/how-to-check-inside-the-worker-thread-if-the-main-ui-thread-is-sleeping-or-not-a 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…