From 6bba111cc692715e26769ba4ad0a48d46330b3f8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 10 Feb 2004 18:21:36 +0000 Subject: [PATCH] added auto check count as otherwise calling EnableAutoCheck() twice in a row resulted in problems git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25712 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/dialup.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/msw/dialup.cpp b/src/msw/dialup.cpp index 70035cfc7a..cf182fb87a 100644 --- a/src/msw/dialup.cpp +++ b/src/msw/dialup.cpp @@ -204,6 +204,10 @@ private: // destroy the thread data and the thread itself void CleanUpThreadData(); + // number of times EnableAutoCheckOnlineStatus() had been called minus the + // number of times DisableAutoCheckOnlineStatus() had been called + int m_autoCheckLevel; + // timer used for polling RAS status class WXDLLEXPORT RasTimer : public wxTimer { @@ -339,6 +343,7 @@ wxDialUpManagerMSW::wxDialUpManagerMSW() m_dllRas(_T("RASAPI32")) { // initialize our data + m_autoCheckLevel = 0; m_hThread = 0; if ( !m_dllRas.IsLoaded() ) @@ -990,6 +995,12 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds) { wxCHECK_MSG( IsOk(), FALSE, wxT("using uninitialized wxDialUpManager") ); + if ( m_autoCheckLevel++ ) + { + // already checking + return TRUE; + } + bool ok = ms_pfnRasConnectionNotification != 0; if ( ok ) @@ -1000,22 +1011,13 @@ bool wxDialUpManagerMSW::EnableAutoCheckOnlineStatus(size_t nSeconds) // first, see if we don't have this thread already running if ( m_hThread != 0 ) { - DWORD dwSuspendCount = 2; - while ( dwSuspendCount > 1 ) - { - dwSuspendCount = ResumeThread(m_hThread); - if ( dwSuspendCount == (DWORD)-1 ) - { - wxLogLastError(wxT("ResumeThread(RasThread)")); + if ( ::ResumeThread(m_hThread) != (DWORD)-1 ) + return TRUE; - ok = FALSE; - } - } + // we're leaving a zombie thread... but what else can we do? + wxLogLastError(wxT("ResumeThread(RasThread)")); - if ( ok ) - { - return TRUE; - } + ok = FALSE; } } @@ -1142,6 +1144,12 @@ void wxDialUpManagerMSW::DisableAutoCheckOnlineStatus() { wxCHECK_RET( IsOk(), wxT("using uninitialized wxDialUpManager") ); + if ( --m_autoCheckLevel ) + { + // still checking + return; + } + if ( m_hThread ) { // we have running secondary thread, it's just enough to suspend it -- 2.47.2