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

View file

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