Comments (5)
This thread is created when NppExec.dll is loaded (i.e. when Notepad++ starts) and this thread spends most of its time here:
::WaitForMultipleObjects(nObjs, hWaitObjs.get(), FALSE, INFINITE)
I.e. it uses 0% of CPU during 99% of the time.
When any file is modified in the "Notepad++\plugins\Config" folder, one of the hWaitObjs
becomes signaled (because of FindFirstChangeNotification
) and NppExec checks whether the last modification time of "npes_saved.txt" is changed or not. If it is changed, NppExec marks this file as "modified" but does not actually re-read this file. This file is re-read only when any script from this file is about to be accessed.
The "NppExec_TechInfo.txt" mentions the WatchScriptFile
opton that can be used to disable the watching.
from nppexec.
The FindFirstChangeNotification
returns a HANDLE
that can be passed to WaitForSingleObject
/WaitForMultipleObjects
:
https://docs.microsoft.com/en-us/windows/win32/fileio/obtaining-directory-change-notifications
The WaitForSingleObject
/WaitForMultipleObjects
returns when there is a change inside the directory being watched.
Then FindNextChangeNotification
must be called to continue to watch the directory.
So it looks logical to introduce a background thread that calls FindFirstChangeNotification
first and then calls FindNextChangeNotification
in a loop.
There is an alternate approach based on ReadDirectoryChangesW
, but its usage is too hardcore even for me with my 20 years of experience with WinAPI :)
from nppexec.
Regarding the background thread - yes, I was referring to myself :) Basically, the main thread is responsible for handling UI actions (such as reacting to menu items, pressing buttons, typing something in NppExec's Console and so on), so background threads are a perfect way to detach the actual processing of some time-consuming operations from UI actions that casue these operations. That is why NppExec's commands and scripts are processed in a background thread - to avoid locking (non-respondence) of the UI while running the commands/scripts. The same is with waiting for the asynchronous result of FindFirstChangeNotification/FindNextChangeNotification (the waiting is done by means of WaitForSingleObject/WaitForMultipleObjects) - a background thread is a perfect way to detach these operations from any other processing.
By the way, you can monitor thread activity and CPU usage via e.g. Process Explorer ( https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer ) or Process Hacker 3 ( https://processhacker.sourceforge.io/nightly.php ).
from nppexec.
Thanks so much for your detailed explanation.
If you're willing, I think you may be able to expand my knowledge a bit.
What is the underlying mechanism that allows hWaitObjs
(via FindFirstChangeNotification
) to be notified of the change to the folder? Is it a new OS thread that gets added to constantly watch the folder? Or is there an existing OS thread always doing this regardless of whether or not nppexec
is running? Or is it a completely different mechanism?
from nppexec.
Thanks. I've read what you wrote, and I'm going to have to come back and read it a few more times.
When you wrote "So it looks logical to introduce a background thread...", were you referring to yourself or the Windows OS? I'm thinking the former, but it's best for me to ask than to guess... :)
from nppexec.
Related Issues (20)
- Techniques to restore cursor position within Notepad++ file HOT 2
- SCI_REPLACE has problem matching the beginning of line HOT 6
- Changing N++ themes results in error HOT 4
- Please add support for theme. I am using version 0.8.2 and the console is white. HOT 1
- Ipython does not have auto-indentation and colour for keywords. The same things work fine in normal command prompt. HOT 5
- encoding characters error HOT 2
- CAnyRichEdit::AddStr() is very slow and should be optimized HOT 1
- Search index for online version of NppExec Manual HOT 14
- How to clean HOT 1
- How to clean up/delete the list saved in F6 HOT 1
- [HTML docs] External links are not navigable HOT 4
- There is something wrong with the console output encoding. HOT 2
- How to get current dir name only (not full path) HOT 2
- License? HOT 4
- XBrackets release accidentally added to this repo? HOT 2
- Double clicking line in console output jumps to the first tab ocurrence if you have multiple tabs open with different files of the same name HOT 4
- im trying to compile a qc file and its saying : ERROR:bad or missing options HOT 1
- Issues getting NppExec console to work with Python's getpass module or third party pwinput module HOT 2
- Notepad++ dev build NPP_OPEN fails HOT 5
- NppExec fails to open file in shellcheck.exe HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nppexec.