On (30 Aug 97) Balog Pal wrote to Jerry Coffin...
BP> I just ran into a problem. Is there something in WIN32 like the
BP> ctirical section in DOS was?
Not really. I'm assuming you mean the function that keeps DOSSHELL
and/or Windows 3.x from switching to another task?
BP> But isn't there a simpler method to prevent a task switch for a short
BP> section in the program? I have a program that is polling directories
BP> and moves the files that apper there to another directories. Another
BP> program creates those files. In several places it simply uses
BP> MoveFileEx itself.
That shouldn't be a problem. If one process attempts to use MoveFileEx
(or MoveFile) on a file while another process has the file open, the
attempt at moving the file will fail.
BP> I found it works in practice. Bus thinking a bit deeper I consider
BP> it's not really safe that way. What if a task switch occours when the
BP> system is in the middle of MoveFileEx?
The OS ensures that moving the file takes place atomically, or at least
appears to do so. I haven't looked at MoveFileEx in particular, but it
can do some tricks to let some task switches take place during lengthy
processes without problems.
However, you might want to take a look at FindFirstChangeNotification or
(better yet) ReadDirectoryChangesW to take care of things even more
simply. It's not entirely clear what you're doing, but from the sound
of things ReadDirectoryChangesW might be your best bet if you can limit
your program to NT. (Even more than many of the OS/2 and UNIX fans, I
can hardly wait for the day Win95 is dead and buried. IMO, restricting
your program to NT is a good first step toward making it more useful and
robust, but unfortunately much of the world hasn't realized this yet.)
Later,
Jerry.
... The Universe is a figment of its own imagination.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)
|