Skip to content

Commit

Permalink
fix for autosync timer in bg thread
Browse files Browse the repository at this point in the history
  • Loading branch information
sepich committed Apr 30, 2015
1 parent 47ff932 commit c3b6244
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions SynNotes/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public partial class Form1 : Form {
TagItem tagAll; // pointer to ALL tag
Dictionary<string, List<scStyle>> lexers = new Dictionary<string, List<scStyle>>(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() {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -441,7 +442,7 @@ private void treeAsList(string query) {
tree.Reveal(tree.SelectedObject, true);
}
else tree.EmptyListMsg = "0 results found";
}, TaskScheduler.FromCurrentSynchronizationContext());
}, ui);

}

Expand Down Expand Up @@ -1433,8 +1434,7 @@ private void timer_sync(object sender, EventArgs e) {
/// <summary>
/// do Simplenote sync
/// </summary>
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<string>(() => {
Expand Down

0 comments on commit c3b6244

Please sign in to comment.