repo base: Start initial remote check in a new thread. Prevents blocking an fixes #321

This commit is contained in:
Hylke Bons 2011-11-13 00:57:00 +00:00
parent 07b727bb72
commit be14c48ae9
2 changed files with 12 additions and 8 deletions

View file

@ -130,6 +130,7 @@ namespace SparkleLib {
public override void AlsoListenTo (string folder_identifier) public override void AlsoListenTo (string folder_identifier)
{ {
string channel = folder_identifier; string channel = folder_identifier;
if (!base.channels.Contains (channel)) { if (!base.channels.Contains (channel)) {
base.channels.Add (channel); base.channels.Add (channel);
@ -139,13 +140,13 @@ namespace SparkleLib {
string to_send = "subscribe " + folder_identifier + "\n"; string to_send = "subscribe " + folder_identifier + "\n";
try { try {
lock (this.mutex) { lock (this.mutex) {
this.socket.Send (Encoding.UTF8.GetBytes (to_send)); this.socket.Send (Encoding.UTF8.GetBytes (to_send));
} }
} catch (SocketException e) { } catch (SocketException e) {
SparkleHelpers.DebugInfo ("ListenerTcp", "Could not connect to " + Server + ": " + e.Message); SparkleHelpers.DebugInfo ("ListenerTcp", "Could not connect to " + Server + ": " + e.Message);
OnDisconnected (); OnDisconnected ();
} }
} }
} }

View file

@ -21,6 +21,7 @@ using System.IO;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading;
using System.Timers; using System.Timers;
using System.Xml; using System.Xml;
@ -41,10 +42,10 @@ namespace SparkleLib {
private SparkleWatcher watcher; private SparkleWatcher watcher;
private TimeSpan poll_interval; private TimeSpan poll_interval;
private Timer local_timer = new Timer () { Interval = 0.25 * 1000 }; private System.Timers.Timer local_timer = new System.Timers.Timer () { Interval = 0.25 * 1000 };
private Timer remote_timer = new Timer () { Interval = 10 * 1000 }; private System.Timers.Timer remote_timer = new System.Timers.Timer () { Interval = 10 * 1000 };
private DateTime last_poll = DateTime.Now; private DateTime last_poll = DateTime.Now;
private List <double> sizebuffer = new List<double> (); private List<double> sizebuffer = new List<double> ();
private bool has_changed = false; private bool has_changed = false;
private Object change_lock = new Object (); private Object change_lock = new Object ();
@ -236,8 +237,10 @@ namespace SparkleLib {
if (this.listener.IsConnected) { if (this.listener.IsConnected) {
this.poll_interval = this.long_interval; this.poll_interval = this.long_interval;
if (!IsSyncing && CheckForRemoteChanges ()) new Thread (new ThreadStart (delegate {
SyncDownBase (); if (!IsSyncing && CheckForRemoteChanges ())
SyncDownBase ();
})).Start ();
} }
// Stop polling when the connection to the irc channel is succesful // Stop polling when the connection to the irc channel is succesful