I am creating a File and at the same time writing 3 lines to this file and then closing the file.

What I wonder is if the fileSystemWatcher has any event that detects when I have done exactly this operation and closed the file.
I want the filesystemwatcher to react After this file is closed and not during writing.

Is that possible ?

String^ Path = "C:\\Folder1\\file1.txt";
FileStream^ hr = new FileStream(Path, FileMode::Create, FileShare::ReadWrite);
StreamWriter^ WriteFile = gcnew StreamWriter(hr);

                for (int i = 0; i < 5; i++)
                {                    
                    WriteFile->WriteLine(Convert::ToString(i));
                }
                WriteFile->Close();//Close file

I try to make the filesystemwatcher to react on the code above where I create the textfile but the Messagebox is not shown when creating the file like this:

private: Void Form1_Load(Object^ sender, EventArgs^ e
{
            fileSystemWatcher1->Path = "C:\\Folder1\\";
            fileSystemWatcher1->Filter = "file1.txt";
            fileSystemWatcher1->EnableRaisingEvents = true;
            fileSystemWatcher1->BeginInit();
}


        private: Void fileSystemWatcher1_Created(Object^ sender, FileSystemEventArgs^ e)
        {
            MessageBox::Show("File is created");
        }

I am creating a File and at the same time writing 3 lines to this file and then closing the file.

What I wonder is if the fileSystemWatcher has any event that detects when I have done exactly this operation and closed the file.
I want the filesystemwatcher to react After this file is closed and not during writing.

Is that possible ?

String^ Path = "C:\\Folder1\\file1.txt";
FileStream^ hr = new FileStream(Path, FileMode::Create, FileShare::ReadWrite);
StreamWriter^ WriteFile = gcnew StreamWriter(hr);

                for (int i = 0; i < 5; i++)
                {                    
                    WriteFile->WriteLine(Convert::ToString(i));
                }
                WriteFile->Close();//Close file

I found out that the Changed event will work fine for this purpose.
Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.