From c3b6244bc5aa38e277f5718c7a4e958c8f66c71f Mon Sep 17 00:00:00 2001 From: sepa Date: Thu, 30 Apr 2015 22:36:48 +0300 Subject: [PATCH] fix for autosync timer in bg thread --- SynNotes/Form.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/SynNotes/Form.cs b/SynNotes/Form.cs index 06760d8..bc8b1de 100644 --- a/SynNotes/Form.cs +++ b/SynNotes/Form.cs @@ -36,9 +36,10 @@ public partial class Form1 : Form { TagItem tagAll; // pointer to ALL tag Dictionary> lexers = new Dictionary>(StringComparer.InvariantCultureIgnoreCase); public static Timer saveTimer; // autosave - public static Timer syncTimer; // auto-sync + public static System.Timers.Timer syncTimer; // auto-sync int treeTopLine, treeSelLine; // used to restore tree position after restore of window string ConnString = ""; //params to connect to db + TaskScheduler ui; #region init/close public Form1() { @@ -78,7 +79,7 @@ private void Form1_Move(object sender, EventArgs e) { //non affecting appearance inits private void Form1_Shown(object sender, EventArgs e) { - var ui = TaskScheduler.FromCurrentSynchronizationContext(); + ui = TaskScheduler.FromCurrentSynchronizationContext(); //delay inits after form drawn Task.Factory.StartNew(() => { // read sync acc @@ -95,15 +96,15 @@ private void Form1_Shown(object sender, EventArgs e) { res = cmd.ExecuteScalar(); if (res != null) Sync.LastSync = int.Parse((string)res); } - //init aut-sync timer + //init auto-sync timer if (syncTimer == null) { - syncTimer = new Timer(); - syncTimer.Tick += timer_sync; + syncTimer = new System.Timers.Timer(); + syncTimer.Elapsed += timer_sync; } if (Sync.Freq != 0) { syncTimer.Interval = Sync.Freq * 60 * 1000; syncTimer.Start(); - SnSync(0, ui);// start full sync on start + SnSync(0); // start full sync on start } }).ContinueWith(t => { // send mouse wheel event to control under cursor @@ -441,7 +442,7 @@ private void treeAsList(string query) { tree.Reveal(tree.SelectedObject, true); } else tree.EmptyListMsg = "0 results found"; - }, TaskScheduler.FromCurrentSynchronizationContext()); + }, ui); } @@ -1433,8 +1434,7 @@ private void timer_sync(object sender, EventArgs e) { /// /// do Simplenote sync /// - private void SnSync(double since, TaskScheduler ui=null) { - if(ui == null) ui = TaskScheduler.FromCurrentSynchronizationContext(); + private void SnSync(double since) { statusText.Text = "Syncing..."; // detach from ui thread Task.Factory.StartNew(() => {