예제 #1
0
        public void StartSync()
        {
            executable.Stopped           += new EventHandler(executable_Stopped);
            executable.Paused            += new EventHandler(executable_Paused);
            executable.ExceptionOccurred += new EventHandler <EventArgs <Exception> >(executable_ExceptionOccurred);

            using (CancellationTokenRegistration registration = cancellationToken.Register(new Action(cancellationToken_Canceled))) {
                executable.Start();
                waitHandle.WaitOne(-1, false);
                waitHandle.Dispose();
            }

            executable.Stopped -= new EventHandler(executable_Stopped);
            executable.Paused  -= new EventHandler(executable_Paused);
            if (executable.ExecutionState == ExecutionState.Started)
            {
                executable.Pause();
            }
            cancellationToken.ThrowIfCancellationRequested();
            if (occuredException != null)
            {
                throw occuredException;
            }
        }