Hello guys,
i know some might complain this should be in the C# section but i wrote it in C++ and also there seems to be more support going on in the C++ section.
I have written some code to monitor multiple files in different directories, essentially i created a seperate thread for each directory and file specified. My question is is this the best approach if i want to monitor multiple files in seperate directories?
here i create the threads for all the files and directories specified
and here is the function invoked:Code:Thread^ t; for(int i = 1; i <= (length-1)/2; i++) { // Supply the state information required by the task. // Create a thread to execute the task, and then // start the thread. t = gcnew Thread(gcnew ThreadStart(gcnew ThreadWithState(args[j],args[j+1]), &ThreadWithState::ThreadProc)); t->Start(); j+=2; } Thread::Sleep(0); Console::WriteLine("Main thread does some work, then waits."); t->Join();
Code:void ThreadProc() { ... ... ........ watcher->NotifyFilter = static_cast<NotifyFilters>(NotifyFilters::LastAccess | NotifyFilters::LastWrite | NotifyFilters::FileName ); watcher->Filter = getFileName(); /*map the events to the corresponding handler / call back function*/ watcher->Changed += gcnew FileSystemEventHandler( ThreadWithState::fileChanged ); watcher->Deleted += gcnew FileSystemEventHandler( ThreadWithState::fileDeleted ); watcher->Created += gcnew FileSystemEventHandler( ThreadWithState::fileCreated ); watcher->Renamed += gcnew RenamedEventHandler( ThreadWithState::fileRenamed ); watcher->EnableRaisingEvents = true; while ( Console::Read() != 'q' ); watcher->EnableRaisingEvents = false; }
essentially it is creating a Filesystemwatcher per file monitored in the directory.
If i wanted to monitor hundreds of files all in seperate directoreis will this be efficient enough?
br



LinkBack URL
About LinkBacks



