News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How to synchronize a database?

Started by NoCforMe, January 10, 2025, 08:33:32 AM

Previous topic - Next topic

sinsi

You shouldn't really use TerminateThread, it's usually a last resort.
Why not set RDCenabled to FALSE and let the thread clean up and exit properly?

Quote from: TerminateThreadTerminateThread is a dangerous function that should only be used in the most extreme cases.

NoCforMe

Quote from: sinsi on January 14, 2025, 07:57:21 PMYou shouldn't really use TerminateThread, it's usually a last resort.
Why not set RDCenabled to FALSE and let the thread clean up and exit properly?

Quote from: TerminateThreadTerminateThread is a dangerous function that should only be used in the most extreme cases.

Good question.
Here's the thing: in the watch routine (RDCmonitor()), ReadDirectoryChangesW is called in an endless loop (unless the flag RDCenabled is set to FALSE). This means that almost all the time, that routine is waiting for ReadDirectoryChangesW to return (called synchronously, remember), so there's no way to check any flags to exit the routine.

There is this code
again: CMP RDCenabled, FALSE
JE exit99
which will exit the thread, but ReadDirectoryChangesW has to complete and return before that can happen.

I tried using ExitThread() outside that routine to shut it down, but that doesn't work. So that's why I use TerminateThread() instead; it reliably terminates the thread (hey, that's why it's called that, huh?), in case you want to change the directory being monitored. Otherwise, you can just leave it running in that infinite loop.

Things would work differently, of course, if you used asynch operation instead, but I haven't tried that yet. This seems to work well and it's simpler.

So I wonder what's so "dangerous" about TerminateThread()?
Assembly language programming should be fun. That's why I do it.

sinsi

CancelSynchronousIo

QuoteMarks pending synchronous I/O operations that are issued by the specified thread as canceled.
Then just check the return status I would guess.

NoCforMe

I'll have to look into using that.
Assembly language programming should be fun. That's why I do it.



zedd151

Quote from: sinsi on January 15, 2025, 06:19:27 AM
Quote from: mabdelouahab on January 15, 2025, 05:28:44 AMFileSystemWatcher
VB.net?

*ducks for cover*

Even worse...
Quote from: FileSystemWatcher_link_from_above...C#

Otherwise known as C Sharp. Might as well be Python.
:badgrin:
¯\_(ツ)_/¯

sinsi

Happy to be the pedant  :biggrin:
Depends on what you viewed last (yes, I just outed myself as a vb.net user :badgrin:)
You cannot view this attachment.

zedd151

Quote from: sinsi on January 15, 2025, 07:10:13 AMDepends on what you viewed last
From the example code in the posted link.  :tongue:




Quote from: sinsi on January 15, 2025, 07:10:13 AM(yes, I just outed myself as a vb.net user :badgrin:)

Blasphemy!  :biggrin:
¯\_(ツ)_/¯

sinsi

My point was that you can change the .net language of the page to suit what you use.
I last used VB.net, so the website remembers that.
You cannot view this attachment.

zedd151

¯\_(ツ)_/¯

NoCforMe

Assembly language programming should be fun. That's why I do it.

NoCforMe

Quote from: sinsi on January 14, 2025, 08:48:20 PMCancelSynchronousIo

QuoteMarks pending synchronous I/O operations that are issued by the specified thread as canceled.
Then just check the return status I would guess.

OK, I give up: why isn't CancelSynchronousIo() in any of the Masm32 include files?

Aaargh; gotta use LoadLibrary() and GetProcAddress().
Assembly language programming should be fun. That's why I do it.

sinsi

Quote from: NoCforMe on January 15, 2025, 12:51:58 PMgotta use LoadLibrary() and GetProcAddress
It's in the Windows 10 SDK kernel32.lib but not MASM32.
Does that mean that MASM32 hasn't been updated to Vista? :dazzled:

zedd151

Quote from: sinsi on January 15, 2025, 01:32:09 PMDoes that mean that MASM32 hasn't been updated to Vista? :dazzled:
Probably since Windows xp.  :tongue: 
¯\_(ツ)_/¯