private void executeRequestSingle(object state) { try { AppSettingsReader _appReader = new AppSettingsReader(); String dbPath = _appReader.GetValue("DataBasePath", typeof(System.String)).ToString(); Int32 nbRecordsToPrint = (Int32)_appReader.GetValue("NbRecordsToPrint", typeof(int)); SelectRequest sr = new SelectRequest(dbPath, _attr._database, nbRecordsToPrint); string request = (string)state; Stopwatch watch = new Stopwatch(); watch.Start(); sr.ExecuteTest(request); watch.Stop(); _multiThreadResult += String.Format("\nDurée d'exécution pour le thread {0} : {1}:{2}:{3}:{4}ms" , Thread.CurrentThread.Name , watch.Elapsed.Hours.ToString().PadLeft(2, '0') , watch.Elapsed.Minutes.ToString().PadLeft(2, '0') , watch.Elapsed.Seconds.ToString().PadLeft(2, '0') , watch.Elapsed.Milliseconds.ToString().PadLeft(3, '0') ); } finally{} }
private void executeRequest(object state) { try { this.Invoke(new Action(() => { this.Cursor = Cursors.WaitCursor; })); toolStrip1.Invoke(new Action(() => { toolStrip1.Enabled = false; })); AppSettingsReader _appReader = new AppSettingsReader(); String cfgPath = _appReader.GetValue("ConfigPath", typeof(System.String)).ToString(); Int32 nbRecordsToPrint = (Int32)_appReader.GetValue("NbRecordsToPrint", typeof(int)); string request = (string)state; Stopwatch watch = new Stopwatch(); watch.Start(); ISelectRequest sr; if ((_attr._odbc_conn_str != null) && (_attr._odbc_conn_str != "")) { sr = new OdbcRequest(_attr._odbc_conn_str); } else if ((_attr._server != "") && (_attr._port != 0)) { sr = new SelectRequestRemote(_attr._server, _attr._port, _attr._database, nbRecordsToPrint); } else { sr = new SelectRequest(cfgPath, _attr._database, nbRecordsToPrint); } System.Data.DataTable dt = sr.Execute(request); watch.Stop(); ssResult.Invoke(new Action(() => { ssResult.Visible = true; })); ssResult.Invoke(new Action(() => { tsslDuration.Visible = true; })); ssResult.Invoke(new Action(() => { tsslNumber.Visible = true; })); scSql.Invoke(new Action(() => { scSql.Panel2Collapsed = false; })); scSql.Invoke(new Action(() => { scSql.SplitterDistance = rtbEditor.Lines.Length * 20; })); ssResult.Invoke(new Action(() => { tsslDuration.Text = String.Format("Durée d'exécution : {0}:{1}:{2}" , watch.Elapsed.Hours.ToString().PadLeft(2, '0') , watch.Elapsed.Minutes.ToString().PadLeft(2, '0') , watch.Elapsed.Seconds.ToString().PadLeft(2, '0') ); })); ssResult.Invoke(new Action(() => { tsslNumber.Text = String.Format("Nombre d'enregistrements : {0})", dt.Rows.Count.ToString()); })); dgResult.Invoke(new Action(() => { dgResult.DataSource = dt; })); _pathFile = sr.PathFile; if (!string.IsNullOrEmpty(_pathFile)) toolStrip1.Invoke(new Action(() => { tsbOpen.Enabled = true; })); } catch (Exception ex) { this.Invoke(new Action(() => { MessageBox.Show("L'exécution de la requête a échoué. \n" + ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } )); } toolStrip1.Invoke(new Action(() => { toolStrip1.Enabled = true; })); this.Invoke(new Action(() => { this.Cursor = Cursors.Default; })); }