locked
Threading with Synchronization fail ? RRS feed

  • Question

  • Hi,

    Currently I am trying to write a program on synchronizing two folders at regular interval. I apply the framework to do the
    synchronization for me, and use System.Threading.Timer to call the method to synchronize folders. The thread simply runs the code as follows:
     Public Sub syncFile()

          ' agent is the  SyncOrchestrator() object, properly initialized
          agent.Synchronize() 
     End Sub

    Everything is fine but the problem occur when I start the program. When the thread runs the code above,
    InvalidCastException occurs as follows:

    System.InvalidCastException was unhandled
      Message="Specified cast is not valid."
      Source="Microsoft.Synchronization"
      StackTrace:
           at Microsoft.Synchronization.CoreInterop.SyncServicesClass.CreateSyncSession(ISyncProvider pDestinationProvider, ISyncProvider pSourceProvider)
           at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWaySyncHelper(SyncIdFormatGroup sourceIdFormats, SyncIdFormatGroup destinationIdFormats, KnowledgeSyncProviderConfiguration destinationConfiguration, SyncCallbacks DestinationCallbacks, ISyncProvider sourceProxy, ISyncProvider destinationProxy, Int32& changesApplied, Int32& changesFailed)
           at Microsoft.Synchronization.KnowledgeSyncOrchestrator.DoOneWayKnowledgeSync(SyncProvider sourceProvider, SyncProvider destinationProvider, Int32& changesApplied, Int32& changesFailed)
           at Microsoft.Synchronization.KnowledgeSyncOrchestrator.Synchronize()
           at Microsoft.Synchronization.SyncOrchestrator.Synchronize()
           at FileSync.FileSync.syncFile() in D:\seconly\FileSync_old\FileSync\FileSync.vb:line 205
           at FileSync.FileSync._Lambda$__1(Object a0) in D:\seconly\FileSync_old\FileSync\FileSync.vb:line 25
           at System.Threading._TimerCallback.TimerCallback_Context(Object state)
           at System.Threading.ExecutionContext.runTryCode(Object userData)
           at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading._TimerCallback.PerformTimerCallback(Object state)
      InnerException:

    The problem occurs for both v1 and v2. Have I done something wrong ?
    Thursday, January 22, 2009 11:45 AM

Answers

  • More details would help:

    From your post so far, to me it seems like there's an invalid casting of the provider instances you have initialized the SyncOrchestrator with.

     

    Are you trying to use File Sync Provider by any chance ?

    If you can post more code, esp around SyncOrchestrator's fields and initializations, it may help more..

     

    Thanks,

    Sameer

    Thursday, January 22, 2009 8:18 PM
  • Oh.... I have found the answer.

    I have started the thread before creating the
    SyncOrchestrator() Object initialized to nothing. That's why it does not work.

    Sorry for any inconvenience caused.
    Friday, January 23, 2009 1:07 AM

All replies

  • More details would help:

    From your post so far, to me it seems like there's an invalid casting of the provider instances you have initialized the SyncOrchestrator with.

     

    Are you trying to use File Sync Provider by any chance ?

    If you can post more code, esp around SyncOrchestrator's fields and initializations, it may help more..

     

    Thanks,

    Sameer

    Thursday, January 22, 2009 8:18 PM
  • Oh.... I have found the answer.

    I have started the thread before creating the
    SyncOrchestrator() Object initialized to nothing. That's why it does not work.

    Sorry for any inconvenience caused.
    Friday, January 23, 2009 1:07 AM