Cancel Sync #989
Cancel Sync
#989
-
follow-up to discussion #836 |
Beta Was this translation helpful? Give feedback.
Answered by
Mimetis
Mar 29, 2023
Replies: 1 comment
-
I used this code for your scenario, where the input from the console decides if we are cancelling or not: var progress = new SynchronousProgress<ProgressArgs>(s =>
Console.WriteLine($"{s.ProgressPercentage:p}: " +
$"\t[{s?.Source?[..Math.Min(4, s.Source.Length)]}] {s.TypeName}: {s.Message}"));
options.DisableConstraintsOnApplyChanges = true;
options.TransactionMode = TransactionMode.PerBatch;
var agent = new SyncAgent(clientProvider, serverProvider, options);
CancellationTokenSource cts = null;
agent.LocalOrchestrator.OnRowsChangesSelected(rcsa =>
{
Console.WriteLine($"OnRowsChangesSelected: {rcsa.SyncRow}");
Console.Write("Cancel sync ? [Y] / [N]: ");
var key = Console.ReadKey();
Console.WriteLine();
if (key != null && key.Key == ConsoleKey.Y)
cts.Cancel();
});
do
{
try
{
Console.ForegroundColor = ConsoleColor.Green;
cts = new CancellationTokenSource();
var s = await agent.SynchronizeAsync(scopeName, setup, SyncType.Normal, null, cts.Token, progress);
Console.WriteLine(s);
}
catch (SyncException e)
{
Console.ResetColor();
Console.WriteLine(e.Message);
}
catch (Exception e)
{
Console.ResetColor();
Console.WriteLine("UNKNOW EXCEPTION : " + e.Message);
}
Console.WriteLine("--------------------");
} while (Console.ReadKey().Key != ConsoleKey.Escape); I've added a row in the client database, then I rollback the sync two times, then I eventually make a complete sync: |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
workgroupengineering
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used this code for your scenario, where the input from the console decides if we are cancelling or not: