none
Check for folder date while another app is running? RRS feed

  • Question

  • So, I have a program that keeps backups from another app and I want to create a backup whenever the files on a specific folder are modified by the other app. This must be done while the program waits the other to close.

    I have the following questions:

    1. Is it possible without wasting the processor's cycles too much?

    2. The code for launching the app goes like this:

    Hide();
                    //Any arguments for the executable (set in this executable's code) are loaded.
                    //So, for example you pass the arguments --LoadFile <file> via code, this will happen:
                    // Run "<Program Folder>\Program.exe" --LoadFile <file>
                    // Set these with _softProcess.Arguments = "argument1 argument2";
                    _softProcess.StartInfo = _softInfo; //Get the arguments from the variable _softInfo
                    //Start the program.
                    _softProcess.Start();
                    //Wait for the game to close before closing Northbridge.
                    _softProcess.WaitForExit();
                    //Calls the Auto-Backup code.
                    if (Settings.Default.AutoBackupEnabled) AutoBackupCode();
                    Close();

    How do I set it up?

    EDIT: I forgot to mention, the app can access and modify multiple files.
    Monday, March 14, 2016 7:59 PM

Answers

  • You can use a FileSystemWatcher class to accomplish this.

    This can be a bit tricky to define correctly so that it logically does the right thing.

    Let's say you want to "archive" (perhaps into a zip file) all the files that a particular program writes to a specific directory.

    You can easily watch the directory for changes.  No problem there.

    Once the first modification is detected, you don't necessarily know if there are more modifications coming.  You don't know if other files are going to be modified or if maybe the process is being restarted and the first file is being modified again.  You should define behaviour that is reasonable in the event that the other process terminates abnormally or runs multiple times before you can react to the file modifications that have been made.

    • Proposed as answer by Kristin Xie Tuesday, March 15, 2016 9:27 AM
    • Marked as answer by AceOfAces_Mod Saturday, March 19, 2016 9:16 PM
    Monday, March 14, 2016 8:24 PM