]> git.saurik.com Git - wxWidgets.git/commitdiff
added auto check count as otherwise calling EnableAutoCheck() twice in a row resulted...
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 10 Feb 2004 18:21:36 +0000 (18:21 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 10 Feb 2004 18:21:36 +0000 (18:21 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25712 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/dialup.cpp

index 70035cfc7a6c5ccc897e5e8b0dddbfb839f3fcad..cf182fb87a25ddb965de1c71a10c88327a3b77cd 100644 (file)
@@ -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