diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 5bebe3bf5..e2d3f912b 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1937,13 +1937,10 @@ void Notepad_plus::command(int id) case IDM_VIEW_MONITORING: { - static HANDLE hThread = nullptr; Buffer * curBuf = _pEditView->getCurrentBuffer(); if (curBuf->isMonitoringOn()) { curBuf->stopMonitoring(); - ::CloseHandle(hThread); - hThread = nullptr; checkMenuItem(IDM_VIEW_MONITORING, false); _toolBar.setCheck(IDM_VIEW_MONITORING, false); curBuf->setUserReadOnly(false); @@ -1963,7 +1960,8 @@ void Notepad_plus::command(int id) curBuf->setUserReadOnly(true); MonitorInfo *monitorInfo = new MonitorInfo(curBuf, _pPublicInterface->getHSelf()); - hThread = ::CreateThread(NULL, 0, monitorFileOnChange, (void *)monitorInfo, 0, NULL); // will be deallocated while quitting thread + HANDLE hThread = ::CreateThread(NULL, 0, monitorFileOnChange, (void *)monitorInfo, 0, NULL); // will be deallocated while quitting thread + ::CloseHandle(hThread); checkMenuItem(IDM_VIEW_MONITORING, true); _toolBar.setCheck(IDM_VIEW_MONITORING, true); } diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index f72274f14..c4e6f2a69 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -648,7 +648,11 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup) if (buf->isMonitoringOn()) { // turn off monitoring - command(IDM_VIEW_MONITORING); + //command(IDM_VIEW_MONITORING); + buf->stopMonitoring(); + checkMenuItem(IDM_VIEW_MONITORING, false); + _toolBar.setCheck(IDM_VIEW_MONITORING, false); + buf->setUserReadOnly(false); } //Do all the works