Scratch Workspace cleanup in SOE service

Discussion created by on Jun 14, 2013
Latest reply on Jun 24, 2013 by

I have a SOE service that does some data processing work. Each time when a new session is created, the service will create a Scratch FileGDB workspace using FileGDBScratchWorkspaceFactory. From Esri document, it says
Second, when the last reference to the workspace is released, the workspace is automatically deleted from the disk.

But I noticed in temp folder where these GDB files locate, the files are still there including the ones created days ago. Basically it is not deleted automatically.

I am wondering in SOE, where should I do the clean up work? here are the codes:

public void Construct(IPropertySet props) //this is the function in SOE main file that reads properties
            configProps = props;
            //load properties

            //Create Scratch Workspace  
           Type factoryType = Type.GetTypeFromProgID(
            IScratchWorkspaceFactory2 scratchWorkspaceFactory = (IScratchWorkspaceFactory2)

            //Get default workspace.
            IWorkspace scratchWorkspace = scratchWorkspaceFactory.DefaultScratchWorkspace;

            if (scratchWorkspace == null) //create a new one
                scratchWorkspace = scratchWorkspaceFactory.CreateNewScratchWorkspace();

What's a good way to clean up scratch workspace? is following method ok?

1. Create a CleanUpScratchWorkspace function: to loop up scratch workspace and delete all datasets within.
2. Put this function inside SOE main file's ShutDown()

I'd like to hear about others' suggestions and appreciate any inputs.