Engines/FlatRedBallXNA/FlatRedBall/Content/ContentBuilder.cs
/// <summary>
/// Ideally, we want to delete our temp directory when we are finished using
/// it. The DeleteTempDirectory method (called by whichever happens first out
/// of Dispose or our finalizer) does exactly that. Trouble is, sometimes
/// these cleanup methods may never execute. For instance if the program
/// crashes, or is halted using the debugger, we never get a chance to do
/// our deleting. The next time we start up, this method checks for any temp
/// directories that were left over by previous runs which failed to shut
/// down cleanly. This makes sure these orphaned directories will not just
/// be left lying around forever.
/// </summary>
Ideally, we want to delete our temp directory when we are finished using
it. The DeleteTempDirectory method (called by whichever happens first out
of Dispose or our finalizer) does exactly that. Trouble is, sometimes
these cleanup methods may never execute. For instance if the program
crashes, or is halted using the debugger, we never get a chance to do
our deleting. The next time we start up, this method checks for any temp
directories that were left over by previous runs which failed to shut
down cleanly. This makes sure these orphaned directories will not just
be left lying around forever.
Ideally we want to delete our temp directory when we are finished using it . The DeleteTempDirectory method ( called by whichever happens first out of Dispose or our finalizer ) does exactly that . Trouble is sometimes these cleanup methods may never execute . For instance if the program crashes or is halted using the debugger we never get a chance to do our deleting . The next time we start up this method checks for any temp directories that were left over by previous runs which failed to shut down cleanly . This makes sure these orphaned directories will not just be left lying around forever .
void PurgeStaleTempDirectories()
        {
            foreach (string directory in Directory.GetDirectories(mBaseDirectory))
            {
                int processId;
                if (int.TryParse(Path.GetFileName(directory), out processId))
                {
                    try
                    {
                        Process.GetProcessById(processId);
                    }
                    catch (ArgumentException)
                    {
                        Directory.Delete(directory, true);
                    }
                }
            }
        }
void PurgeStaleTempDirectories ( ) { foreach ( string directory in Directory . GetDirectories ( mBaseDirectory ) ) { int processId ; if ( int . TryParse ( Path . GetFileName ( directory ) , out processId ) ) { try { Process . GetProcessById ( processId ) ; } catch ( ArgumentException ) { Directory . Delete ( directory , true ) ; } } } }
Ideally, we want to delete our temp directory when we are finished using
it.
Ideally we want to delete our temp directory when we are finished using it .
// Check all subdirectories of our base location. // The subdirectory name is the ID of the process which created it. // Is the creator process still running? // If the process is gone, we can delete its temp directory.