diff --git a/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.cpp b/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.cpp
index ed01661a447c04af949d9c5295fb0d6920424df7..e58a405aa703172280b0f58592b35ea42896b5df 100644
--- a/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.cpp
+++ b/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.cpp
@@ -23,9 +23,6 @@
  *     You should have received a copy of the GNU General Public License
  *     along with XTPcpp.  If not, see <http://www.gnu.org/licenses/>.
  *
- * Contributors:
- *     Olivier Langella <olivier.langella@u-psud.fr> - initial API and
- *implementation
  ******************************************************************************/
 
 #include "exportmasschroqdialog.h"
@@ -39,11 +36,13 @@
 #include <pappsomspp/msrun/alignment/msrunretentiontime.h>
 #include <pappsomspp/msfile/msfileaccessor.h>
 #include <pappsomspp/pappsoexception.h>
+#include "../../mainwindow.h"
 
-ExportMasschroqDialog::ExportMasschroqDialog(QWidget *parent)
+ExportMasschroqDialog::ExportMasschroqDialog(MainWindow *parent)
   : QDialog(parent), ui(new Ui::ExportMasschroqDialog)
 {
   qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
+  mp_main = parent;
   ui->setupUi(this);
   this->setModal(true);
 
@@ -68,9 +67,9 @@ ExportMasschroqDialog::~ExportMasschroqDialog()
 }
 
 void
-ExportMasschroqDialog::setProject(const Project *p_project)
+ExportMasschroqDialog::setProjectSPtr(ProjectSp p_project)
 {
-  mp_project = p_project;
+  msp_project = p_project;
   fillMsrunListComboBox();
 }
 
@@ -160,6 +159,13 @@ ExportMasschroqDialog::getMasschroqFileParameters() const
 }
 
 
+void
+ExportMasschroqDialog::reject()
+{
+  msp_project = nullptr;
+  QDialog::reject();
+}
+
 void
 ExportMasschroqDialog::accept()
 {
@@ -203,6 +209,7 @@ ExportMasschroqDialog::accept()
     {
       ZivyParams zivy_params = ui->zivyParamWidget->getZivyParams();
       zivy_params.saveSettings();
+      msp_project = nullptr;
       QDialog::accept();
     }
   else
@@ -223,7 +230,7 @@ ExportMasschroqDialog::doCheckMsrunFilepath()
   ui->msrunFilepathOkLabel->setHidden(true);
   bool is_ok = true;
   for(IdentificationDataSourceSp p_ident_data_source :
-      mp_project->getIdentificationDataSourceStore()
+      msp_project->getIdentificationDataSourceStore()
         .getIdentificationDataSourceList())
     {
       MsRunSp msrun_sp = p_ident_data_source->getMsRunSp();
@@ -279,105 +286,133 @@ ExportMasschroqDialog::doBrowseMsrunDirectory()
 void
 ExportMasschroqDialog::doFindBestMsrunForAlignment()
 {
-  bool is_ok = true;
-  for(auto &msrun_sp : mp_project->getMsRunStore().getMsRunList())
-    {
-      if(msrun_sp->findMsRunFile())
-        {
-        }
-      else
-        {
-          is_ok = false;
-          ui->warningDirectoryLabel->setText(
-            tr("%1 not found : Please choose the directory to look for this MS "
-               "run file.")
-              .arg(msrun_sp.get()->getFileName()));
-          ui->directorySelectWidget->setHidden(false);
-          break;
-        }
-    }
-  try
-    {
-      mp_project->prepareMsrunRetentionTimesForAlignment();
-
-      MsRunSp ms_run_best_reference;
-      std::size_t best_number = 0;
-      for(auto &msrun_ref_sp : mp_project->getMsRunStore().getMsRunList())
-        {
-          if(ms_run_best_reference == nullptr)
-            {
-              ms_run_best_reference = msrun_ref_sp;
-            }
+  mp_main->showWaitingMessage(tr("Looking for MSrun reference"));
+  emit operateFindBestMsrunForAlignment(msp_project);
+  /*
+bool is_ok = true;
+for(auto &msrun_sp : msp_project->getMsRunStore().getMsRunList())
+  {
+    if(msrun_sp->findMsRunFile())
+      {
+      }
+    else
+      {
+        is_ok = false;
+        ui->warningDirectoryLabel->setText(
+          tr("%1 not found : Please choose the directory to look for this MS "
+             "run file.")
+            .arg(msrun_sp.get()->getFileName()));
+        ui->directorySelectWidget->setHidden(false);
+        break;
+      }
+  }
+try
+  {
+    msp_project->prepareMsrunRetentionTimesForAlignment();
+
+    MsRunSp ms_run_best_reference;
+    std::size_t best_number = 0;
+    for(auto &msrun_ref_sp : msp_project->getMsRunStore().getMsRunList())
+      {
+        if(ms_run_best_reference == nullptr)
+          {
+            ms_run_best_reference = msrun_ref_sp;
+          }
+
+        std::size_t min_number = std::numeric_limits<std::size_t>::max();
+        for(auto &msrun_sp : msp_project->getMsRunStore().getMsRunList())
+          {
+            if(msrun_sp.get() != msrun_ref_sp.get())
+              {
+                pappso::Trace trace;
+                trace = msrun_sp.get()
+                          ->getMsRunRetentionTimePtr()
+                          ->getCommonDeltaRt(msrun_ref_sp.get()
+                                               ->getMsRunRetentionTimePtr()
+                                               ->getSeamarks());
+                if(trace.size() < min_number)
+                  {
+                    min_number = trace.size();
+                  }
+              }
+          }
+
+        if(min_number > best_number)
+          {
+            best_number = min_number;
+
+            ms_run_best_reference = msrun_ref_sp;
+          }
+      }
+    if(ms_run_best_reference != nullptr)
+      {
+        qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
+                 << ms_run_best_reference.get()->getXmlId()
+                 << " best_number=" << best_number;
+
+        for(int index = 0; index < ui->msrun_list_combo_box->count(); index++)
+          {
+            MsRunSp msrun_sp = qvariant_cast<MsRunSp>(
+              ui->msrun_list_combo_box->itemData(index));
+            if(msrun_sp.get() == ms_run_best_reference.get())
+              {
+                ui->msrun_list_combo_box->setCurrentIndex(index);
+              }
+          }
+      }
+  }
+catch(pappso::PappsoException &error)
+  {
+    QMessageBox msgBox;
+    msgBox.setWindowTitle("Error");
+    msgBox.setText(
+      tr("Error preparing MS run retention times: %1").arg(error.qwhat()));
+    msgBox.setIcon(QMessageBox::Critical);
+    msgBox.exec();
+  }
+  */
+}
 
-          std::size_t min_number = std::numeric_limits<std::size_t>::max();
-          for(auto &msrun_sp : mp_project->getMsRunStore().getMsRunList())
-            {
-              if(msrun_sp.get() != msrun_ref_sp.get())
-                {
-                  pappso::Trace trace;
-                  trace = msrun_sp.get()
-                            ->getMsRunRetentionTimePtr()
-                            ->getCommonDeltaRt(msrun_ref_sp.get()
-                                                 ->getMsRunRetentionTimePtr()
-                                                 ->getSeamarks());
-                  if(trace.size() < min_number)
-                    {
-                      min_number = trace.size();
-                    }
-                }
-            }
+void
+ExportMasschroqDialog::setBestMsrunForAlignment(MsRunSp best_msrun_sp)
+{
 
-          if(min_number > best_number)
-            {
-              best_number = min_number;
+  mp_main->hideWaitingMessage();
+  if(best_msrun_sp != nullptr)
+    {
+      qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
+               << best_msrun_sp.get()->getXmlId();
 
-              ms_run_best_reference = msrun_ref_sp;
-            }
-        }
-      if(ms_run_best_reference != nullptr)
+      for(int index = 0; index < ui->msrun_list_combo_box->count(); index++)
         {
-          qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
-                   << ms_run_best_reference.get()->getXmlId()
-                   << " best_number=" << best_number;
-
-          for(int index = 0; index < ui->msrun_list_combo_box->count(); index++)
+          MsRunSp msrun_sp =
+            qvariant_cast<MsRunSp>(ui->msrun_list_combo_box->itemData(index));
+          if(msrun_sp.get() == best_msrun_sp.get())
             {
-              MsRunSp msrun_sp = qvariant_cast<MsRunSp>(
-                ui->msrun_list_combo_box->itemData(index));
-              if(msrun_sp.get() == ms_run_best_reference.get())
-                {
-                  ui->msrun_list_combo_box->setCurrentIndex(index);
-                }
+              ui->msrun_list_combo_box->setCurrentIndex(index);
             }
         }
     }
-  catch(pappso::PappsoException &error)
-    {
-      QMessageBox msgBox;
-      msgBox.setWindowTitle("Error");
-      msgBox.setText(
-        tr("Error preparing MS run retention times: %1").arg(error.qwhat()));
-      msgBox.setIcon(QMessageBox::Critical);
-      msgBox.exec();
-    }
 }
 
-
 void
 ExportMasschroqDialog::fillMsrunListComboBox()
 {
   ui->msrun_list_combo_box->clear();
-
-  int index = -1;
-  for(auto &msrun_sp : mp_project->getMsRunStore().getMsRunList())
+  if(msp_project != nullptr)
     {
-      index = 0;
-      ui->msrun_list_combo_box->addItem(
-        QString("%1").arg(msrun_sp.get()->getSampleName()),
-        QVariant::fromValue(msrun_sp));
-    }
-  if(index != -1)
-    { // -1 for not found
-      ui->msrun_list_combo_box->setCurrentIndex(index);
+
+      int index = -1;
+      for(auto &msrun_sp : msp_project->getMsRunStore().getMsRunList())
+        {
+          index = 0;
+          ui->msrun_list_combo_box->addItem(
+            QString("%1").arg(msrun_sp.get()->getSampleName()),
+            QVariant::fromValue(msrun_sp));
+        }
+      if(index != -1)
+        { // -1 for not found
+          ui->msrun_list_combo_box->setCurrentIndex(index);
+        }
     }
 }
diff --git a/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.h b/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.h
index 005ed7b0c51a9f7a1dddf64967df0d5827cf4700..18d2c14dd73f03a18268694f2bef8eb74b6919c6 100644
--- a/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.h
+++ b/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.h
@@ -39,25 +39,36 @@ namespace Ui
 class ExportMasschroqDialog;
 }
 
+class MainWindow;
+
 class ExportMasschroqDialog : public QDialog
 {
   Q_OBJECT
 
 
   public:
-  explicit ExportMasschroqDialog(QWidget *parent);
+  explicit ExportMasschroqDialog(MainWindow *parent);
   ~ExportMasschroqDialog();
   void accept() override;
+  void reject() override;
 
   void setMasschroqFileParameters(const MasschroqFileParameters &params);
   MasschroqFileParameters getMasschroqFileParameters() const;
 
-  void setProject(const Project *p_project);
+  void setProjectSPtr(ProjectSp p_project);
+
+  signals:
+  // void peptideChanged(pappso::PeptideSp peptide);
+  void operateFindBestMsrunForAlignment(ProjectSp project_sp);
+
 
+  public slots:
+  void setBestMsrunForAlignment(MsRunSp msrun_sp);
 
   private:
   Ui::ExportMasschroqDialog *ui;
-  const Project *mp_project;
+  ProjectSp msp_project;
+  MainWindow *mp_main;
 
   protected slots:
   void doCheckMsrunFilepath();
diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp
index bce4fb0def3d1e3d375613fcc3999fb77b5f2ebc..4dfdb40e28fd43d8d6de609d893adee0ce24d7b5 100644
--- a/src/gui/mainwindow.cpp
+++ b/src/gui/mainwindow.cpp
@@ -33,7 +33,6 @@
 #include "ui_main.h"
 #include <pappsomspp/pappsoexception.h>
 #include "../utils/utils.h"
-#include "workerthread.h"
 #include "output/xpip.h"
 #include "export/export_masschroq_dialog/masschroqfileparameters.h"
 
@@ -45,8 +44,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::Main)
   setWindowTitle(QString("%1 %2").arg(SOFTWARE_NAME).arg(XTPCPP_VERSION));
   setWindowIcon(QIcon(":/xtpcpp_icon/resources/xtandempipeline_icon.svg"));
 
-  WorkerThread *worker = new WorkerThread(this);
-  worker->moveToThread(&_worker_thread);
+  mp_worker = new WorkerThread(this);
+  mp_worker->moveToThread(&_worker_thread);
   _worker_thread.start();
 
   _p_load_results_dialog       = new LoadResultsDialog(this);
@@ -577,6 +576,16 @@ MainWindow::doActionMassChroQ()
                   &ExportMasschroqDialog::accepted,
                   this,
                   &MainWindow::doAcceptedExportMasschroqDialog);
+
+          connect(_p_export_masschroq_dialog,
+                  &ExportMasschroqDialog::operateFindBestMsrunForAlignment,
+                  mp_worker,
+                  &WorkerThread::doFindBestMsrunForAlignment);
+
+          connect(mp_worker,
+                  &WorkerThread::findingBestMsrunForAlignmentFinished,
+                  _p_export_masschroq_dialog,
+                  &ExportMasschroqDialog::setBestMsrunForAlignment);
         }
 
       MasschroqFileParameters params;
@@ -584,7 +593,7 @@ MainWindow::doActionMassChroQ()
       if(_project_sp.get() != nullptr)
         {
           _p_export_masschroq_dialog->setMasschroqFileParameters(params);
-          _p_export_masschroq_dialog->setProject(this->_project_sp.get());
+          _p_export_masschroq_dialog->setProjectSPtr(this->_project_sp);
         }
       _p_export_masschroq_dialog->show();
       _p_export_masschroq_dialog->raise();
diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h
index ff285e4a766b676c2a74d5d687284963f4d8162a..4ec575c57ec69718d2ba48f19cff8c88d244f943 100644
--- a/src/gui/mainwindow.h
+++ b/src/gui/mainwindow.h
@@ -42,6 +42,7 @@
 #include "utils/httpversion.h"
 #include "gui/edit/edit_settings/editsettings.h"
 #include "gui/export/export_masschroq_dialog/exportmasschroqdialog.h"
+#include "workerthread.h"
 
 
 namespace Ui
@@ -127,7 +128,7 @@ class MainWindow : public QMainWindow
   void setProjectSp(ProjectSp project_sp);
 
 
-  private:
+  public:
   void showWaitingMessage(const QString title);
   void hideWaitingMessage();
   void viewError(QString error);
@@ -136,6 +137,8 @@ class MainWindow : public QMainWindow
   QCoreApplication *_p_app;
   Ui::Main *ui;
   QThread _worker_thread;
+  WorkerThread *mp_worker;
+
   ProjectSp _project_sp = nullptr;
 
   ProjectWindow *_project_window                        = nullptr;
diff --git a/src/gui/workerthread.cpp b/src/gui/workerthread.cpp
index e4fb6277f21c5f781141294df6ab571149bb23b9..f8a272924fb254619a467be2fd9ead3bbe881583 100644
--- a/src/gui/workerthread.cpp
+++ b/src/gui/workerthread.cpp
@@ -776,3 +776,79 @@ WorkerThread::doWritingFastaFile(QString filename,
         tr("Error while writing FASTA file :\n%1").arg(error.qwhat()));
     }
 }
+
+
+void
+WorkerThread::doFindBestMsrunForAlignment(ProjectSp project_sp)
+{
+
+  try
+    {
+
+      qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
+      emit loadingMessage(tr("looking for the best MSrun reference for alignment, please wait"));
+
+
+      bool is_ok = true;
+      for(auto &msrun_sp : project_sp->getMsRunStore().getMsRunList())
+        {
+          if(msrun_sp->findMsRunFile())
+            {
+            }
+          else
+            {
+            }
+        }
+      project_sp->prepareMsrunRetentionTimesForAlignment();
+
+      MsRunSp ms_run_best_reference;
+      std::size_t best_number = 0;
+      for(auto &msrun_ref_sp : project_sp->getMsRunStore().getMsRunList())
+        {
+          if(ms_run_best_reference == nullptr)
+            {
+              ms_run_best_reference = msrun_ref_sp;
+            }
+
+          std::size_t min_number = std::numeric_limits<std::size_t>::max();
+          for(auto &msrun_sp : project_sp->getMsRunStore().getMsRunList())
+            {
+              if(msrun_sp.get() != msrun_ref_sp.get())
+                {
+                  pappso::Trace trace;
+                  trace = msrun_sp.get()
+                            ->getMsRunRetentionTimePtr()
+                            ->getCommonDeltaRt(msrun_ref_sp.get()
+                                                 ->getMsRunRetentionTimePtr()
+                                                 ->getSeamarks());
+                  if(trace.size() < min_number)
+                    {
+                      min_number = trace.size();
+                    }
+                }
+            }
+
+          if(min_number > best_number)
+            {
+              best_number = min_number;
+
+              ms_run_best_reference = msrun_ref_sp;
+            }
+        }
+      if(ms_run_best_reference != nullptr)
+        {
+          qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
+                   << ms_run_best_reference.get()->getXmlId()
+                   << " best_number=" << best_number;
+        }
+
+      // emit operateXpipFile(filename);
+      emit findingBestMsrunForAlignmentFinished(ms_run_best_reference);
+    }
+  catch(pappso::PappsoException &error)
+    {
+      emit operationFailed(
+        tr("Error looking for the best MSrun reference for alignment :\n%1")
+          .arg(error.qwhat()));
+    }
+}
diff --git a/src/gui/workerthread.h b/src/gui/workerthread.h
index 3929b9d2f0015a4842d1d810e14895211d6c1255..f2e959a8f5300d4fce660eb201ffd2c4c54fe6e8 100644
--- a/src/gui/workerthread.h
+++ b/src/gui/workerthread.h
@@ -28,8 +28,7 @@
  *implementation
  ******************************************************************************/
 
-#ifndef WORKERTHREAD_H
-#define WORKERTHREAD_H
+#pragma once
 
 #include <QThread>
 #include <QCloseEvent>
@@ -57,16 +56,19 @@ class WorkerThread : public QObject
 
   public slots:
   void doXpipFileLoad(QString filename);
-  void doLoadingResults(bool is_individual, AutomaticFilterParameters param,
+  void doLoadingResults(bool is_individual,
+                        AutomaticFilterParameters param,
                         QStringList file_list);
   void doWritingXpipFile(QString filename, ProjectSp project_sp);
   void doWritingOdsFile(QString filename, QString format, ProjectSp project_sp);
-  void doWritingMassChroqFile(QString filename, ProjectSp project_sp,
+  void doWritingMassChroqFile(QString filename,
+                              ProjectSp project_sp,
                               MasschroqFileParameters params);
   void doWritingMassChroqPrmFile(QString filename, ProjectSp project_sp);
   void doWritingProticFile(QString filename, ProjectSp project_sp);
   void doWritingMcqrSpectralCountFile(QString filename, ProjectSp project_sp);
-  void doWritingFastaFile(QString filename, ProjectSp project_sp,
+  void doWritingFastaFile(QString filename,
+                          ProjectSp project_sp,
                           ExportFastaType type);
   void doGrouping(ProjectSp project_sp);
   void doGroupingOnIdentification(IdentificationGroup *p_identification_group,
@@ -74,6 +76,7 @@ class WorkerThread : public QObject
   void
   doPtmGroupingOnIdentification(IdentificationGroup *p_identification_group);
   void doRunningXtandem(TandemRunBatch tandem_run_batch);
+  void doFindBestMsrunForAlignment(ProjectSp project_sp);
 
 
   signals:
@@ -88,10 +91,9 @@ class WorkerThread : public QObject
     IdentificationGroup *p_identification_group);
   void operationFinished();
   void operationFailed(QString error);
+  void findingBestMsrunForAlignmentFinished(MsRunSp msrun_sp);
 
   private:
   WorkMonitor *_p_work_monitor;
   MainWindow *_p_main_window;
 };
-
-#endif // WORKERTHREAD_H