Index: trunk/BNC/upload/bncuploadcaster.cpp
===================================================================
--- trunk/BNC/upload/bncuploadcaster.cpp	(revision 3207)
+++ trunk/BNC/upload/bncuploadcaster.cpp	(revision 3208)
@@ -193,4 +193,7 @@
   QMutexLocker locker(&_mutex);
   _isToBeDeleted = true;
+  if (!isRunning()) {
+    delete this;
+  }
 }
 
@@ -198,4 +201,7 @@
 ////////////////////////////////////////////////////////////////////////////
 bncUploadCaster::~bncUploadCaster() {
+  if (isRunning()) {
+    wait();
+  }
   if (_ephMap) {
     QMapIterator<QString, t_eph*> it(*_ephMap);
@@ -216,4 +222,12 @@
 void bncUploadCaster::run() {
   while (true) {
+    {
+      QMutexLocker locker(&_mutex);
+      if (_isToBeDeleted) {
+        QThread::quit();
+        deleteLater();
+        return;
+      }
+    }
     uploadClockOrbitBias();
     msleep(10);
@@ -346,12 +360,4 @@
 
   QMutexLocker locker(&_mutex);
-
-  // Safely stop and delete
-  // ----------------------
-  if (_isToBeDeleted) {
-    QThread::quit();
-    deleteLater();
-    return;
-  }
 
   // Prepare list of lines with satellite positions in SP3-like format
