🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #10041

Re: Using Damon Chandler's FindNextChangeNotification example

#10041
From: Remy Lebeau (TeamB)
Date: Sun, 23 May 2004 20:41
96 lines
3531 bytes
"JD" <nospam@nospam.com> wrote in message
news:40b0d61d$1@newsgroups.borland.com...

> I still get double notification with a single change using
> WaitForMultipleObjects and no notification at all if I use
> WaitForSingleObject (which does not error).

The following code works fine for me, and does not produce double
notifications at all:

    --- TMonitorThread.h ---

    #define APPWM_CHANGED (WM_APP+100)

    class TMonitorThread : public TThread
    {
    private:
        AnsiString FPath;
    protected:
        void __fastcall Execute();
    public:
        __fastcall TMonitorThread(const AnsiString &Path);
    };


    --- TMonitorThread.cpp ---

    __fastcall TMonitorThread::TMonitorThread(const AnsiString &Path)
        : TThread(true)
    {
        FPath = Path;
        Resume();
    }

    void __fastcall TMonitorThread::Execute()
    {
        HANDLE hFind = FindFirstChangeNotification(FPath.c_str(), FALSE,
FILE_NOTIFY_CHANGE_LAST_WRITE);
        if( hFind != INVALID_HANDLE_VALUE )
        {
            while( !Terminated )
            {
                switch( WaitForSingleObject(hFind, 500) )
                {
                    case WAIT_OBJECT_0:
                        PostMessage(Application->MainForm->Handle,
APPWM_CHANGED, 0, 0);
                        if( !FindNextChangeNotification(hFind) )
                            Terminate();
                        break;

                    case WAIT_TIMEOUT:
                        // keep waiting...
                        break;

                    default:
                        Terminate();
                        break;
                }
            }

            FindCloseChangeNotification(hFind);
        }
    }


    --- Unit1.cpp ---

    #include "TMonitorThread.h"

    TMonitorThread *Thread = NULL;

    __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
    {
        Thread = new TMonitorThread("C:\\");
    }

    __fastcall TForm1::~TForm1()
    {
        Thread->Terminate();
        Thread->WaitFor();
        delete Thread;
    }

    void __fastcall TForm1::WndProc(TMessage &Message)
    {
        if( Message.Msg == APPWM_CHANGED )
            ShowMessage("changed");
        else
            TForm::WndProc(Message);
    }


Gambit
Technical Details
Message-ID: <40b10d80$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <40ade94f$1@newsgroups.borland.com> <40af63b7$1@newsgroups.borland.com> <40af8def$1@newsgroups.borland.com> <40afda3f$1@newsgroups.borland.com> <40b0233e$1@newsgroups.borland.com> <40b030d4$1@newsgroups.borland.com> <40b0d61d$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,32a59cffbb6bea4a
X-Google-Attributes: gid10cc67,public
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <40ade94f$1@newsgroups.borland.com> <40af63b7$1@newsgroups.borland.com> <40af8def$1@newsgroups.borland.com> <40afda3f$1@newsgroups.borland.com> <40b0233e$1@newsgroups.borland.com> <40b030d4$1@newsgroups.borland.com> <40b0d61d$1@newsgroups.borland.com>
Subject: Re: Using Damon Chandler's FindNextChangeNotification example
Date: Sun, 23 May 2004 13:41:01 -0700
Lines: 98
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 67.22.135.163
Message-ID: <40b10d80$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1085345152 67.22.135.163 (23 May 2004 13:45:52 -0700)
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail