locked
The process cannot access the file because it is being used by another process. RRS feed

  • Question

  • Hello,

    I am developong a sync application by using sync framework. the  purpose is to sync the files on the specified paths across the globe.
    but the it is giving error as below:

    The process cannot access the file '\\GBEDC\Bettis\Fareham Office\Engineering\SEParts\filesync.metadata' because it is being used by another process.

    following is the code written for the syncronization.

    public void Synchronize()
    
    {
    
    		FileSyncOptions options = FileSyncOptions.RecycleConflictLoserFiles | FileSyncOptions.RecycleDeletedFiles | FileSyncOptions.RecyclePreviousFileOnUpdates;
                        FileSyncScopeFilter filter = new FileSyncScopeFilter();
                        filter.FileNameExcludes.Add(idFileName); // Exclude the id file i.e. Myfilesync.id
                        filter.FileNameExcludes.Add("Thumbs.db");
                        filter.FileNameExcludes.Add("filesync.metadata");
                        for (int serInfo = 1; serInfo < MyServerInfo.Count; serInfo++)
                        {
                            SyncFileSystemReplicasOneWay((SyncId)MySyncId[0], (SyncId)MySyncId[serInfo], MyServerInfo[0].ToString(), MyServerInfo[serInfo].ToString(), filter, options, MySerLocInfo[0].ToString(), MySerLocInfo[serInfo].ToString());
                        }
    
                        for (int serInfo = 1; serInfo < MyServerInfo.Count; serInfo++)
                        {
                            SyncFileSystemReplicasOneWay((SyncId)MySyncId[serInfo], (SyncId)MySyncId[0], MyServerInfo[serInfo].ToString(), MyServerInfo[0].ToString(), filter, options, MySerLocInfo[serInfo].ToString(), MySerLocInfo[0].ToString());
                        }
    }
    
    
    
    public void SyncFileSystemReplicasOneWay(SyncId sourceReplicaId, SyncId destinationReplicaId, string sourceReplicaRootPath, string destinationReplicaRootPath, FileSyncScopeFilter filter, FileSyncOptions options, string SLoc, string DesLoc)
    {
                FileSyncProvider sourceProvider = new FileSyncProvider(sourceReplicaId.GetGuidId(), sourceReplicaRootPath, filter, options);
                FileSyncProvider destinationProvider = new FileSyncProvider(destinationReplicaId.GetGuidId(), destinationReplicaRootPath, filter, options);
    
                Monitor.Enter(sourceProvider);
                Monitor.Enter(destinationProvider);
    
                try
                {
                    sourceProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange);
                    destinationProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange);
                    
    sourceProvider.SkippedChange += new EventHandler<SkippedChangeEventArgs>(OnSkippedChange); destinationProvider.SkippedChange += new EventHandler<SkippedChangeEventArgs>(OnSkippedChange); sourceProvider.CopyingFile += new EventHandler<CopyingFileEventArgs>(OnCopyingFile); destinationProvider.CopyingFile += new EventHandler<CopyingFileEventArgs>(OnCopyingFile); StreamWriter sw = new StreamWriter(strfile, true); string strSynchInfo = "Synchronizing : " + SLoc + " (" + sourceProvider.RootDirectoryPath + ")" + " From : " + DesLoc + " (" + destinationProvider.RootDirectoryPath + ")"; sw.WriteLine(strSynchInfo); sw.WriteLine("----------------------------------------------------------------------------------------------------------------------------"); sw.Close(); SetToolStripLable(toolStripStatusBarLabel, strSynchInfo); SyncOrchestrator agent = new SyncOrchestrator(); agent.LocalProvider = sourceProvider; agent.RemoteProvider = destinationProvider; agent.Direction = SyncDirectionOrder.Download; // Sync source to destination strSPath = sourceProvider.RootDirectoryPath; SyncOperationStatistics sstat = agent.Synchronize(); StreamWriter sw1 = new StreamWriter(strfile, true); sw1.WriteLine("Successfully Completed... Sync Start Time = " + sstat.SyncStartTime.ToString() + " Sync End Time = " + sstat.SyncEndTime.ToString()); sw1.WriteLine("---------------------------------------------------------------------------------------------------------------------------"); sw1.Close(); } catch(Exception ex) { CErrorLog m_errLog = new CErrorLog(m_Common.errLogFile); m_errLog.AddToErrorLog(ex.Message, "FileSynchronizer /SyncFileSystemReplicasOneWay"); } finally { // Release resources Monitor.Exit(sourceProvider); Monitor.Exit(destinationProvider); } }
    is there any other settings required to avoid the error mentioned above.

    please advice!!!

    let me know if any other clarifications required.


    Shiv S.Kushwaha
    • Moved by Max Wang_1983 Thursday, April 21, 2011 1:15 AM forum consolidation (From:SyncFx - Technical Discussion [ReadOnly])
    Monday, July 20, 2009 5:09 AM

Answers

  • Hi -
    In your SyncFileSystemReplicasOneWay code - in the finally you need to dispose the two FileSystemProvider objects that you created at the beginning of the code.


    Thanks
    Deepa

    Deepa ( Microsoft Sync Framework)
    Tuesday, July 28, 2009 7:36 PM
    Answerer