private void LoadClimbers(object obj) { bool threadAbort = false; loadAgr la = obj as loadAgr; if (la == null) { return; } try { SqlConnection lCn, rCn; if (la.compForService == null) { if (la.useCurrent) { rCn = remoteConnection; } else { rCn = new SqlConnection(remoteConnection.ConnectionString); } } else { rCn = null; } if (la.useCurrent) { lCn = cn; } else { lCn = new SqlConnection(cn.ConnectionString); } try { StaticClass.RefreshClimberList(true, true, la.loadPhoto, la.compForService, lCn, rCn, la.Client); //if (la.loadJudges) // StaticClass.RefreshJudgesList(true, true, la.loadPhoto, lCn, rCn); } catch (System.Threading.ThreadAbortException) { threadAbort = true; } finally { if (!la.useCurrent) { try { lCn.Close(); } catch { } if (rCn != null) { try { rCn.Close(); } catch { } } } } } catch (ThreadAbortException) { threadAbort = true; } #if !DEBUG catch { } #endif finally { if (!threadAbort) { try { if (la != null && la.Callback != null) { la.Callback(MainForm.ThreadStats.IMG_SAV_REM); } } catch { } } } }
private void btnLoadClimbers_Click(object sender, EventArgs e) { try { this.ReloadClimbersList(); } catch (Exception ex) { MessageBox.Show(String.Format("Ошибка обновления: {0}", ex)); } return; if (client != null) { if (cbLoadInDiffThread.Checked) { lock (loaderLocker) { if (climbersLoadingResult != null) { if (MessageBox.Show(this, "Загрузка запущена. Прервать?", String.Empty, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { climbersLoadingResult.Abort(); } else { return; } } climbersLoadingResult = OnlineUpdater.BeginRefreshClimbers(true, cn, client, UpdateCompleted, null); } } else { try { OnlineUpdater.RefreshClimbers(true, cn, client, true); StaticClass.ShowExceptionMessageBox("Список участников успешно загружен", owner: this); } catch (WebException wex) { StaticClass.ShowExceptionMessageBox("Ошибка обновления сайта", wex, this); } catch (SqlException s) { StaticClass.ShowExceptionMessageBox("Ошибка работы с данными", s, this); } catch (Exception ex) { StaticClass.ShowExceptionMessageBox("Неизвестная ошибка", ex, this); } } return; } loadAgr la = new loadAgr(!cbLoadInDiffThread.Checked, cbLoadPhoto.Checked, cbLoadJudges.Checked, compForService, client, new MainForm.AfetrStopCallBack(parent.RemThrData), cn); if (la.useCurrent) { LoadClimbers(la); } else { if (parent.LoadingThread != null && parent.LoadingThread.IsAlive) { if (MessageBox.Show("Загрузка списка участников уже запущена. Прервать?", "Загрузка запущена", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { return; } } parent.LoadingThread = new Thread(LoadClimbers); MainForm.ThrData td = new MainForm.ThrData(parent.LoadingThread, MainForm.ThreadStats.IMG_SAV_REM); parent.AddThrData(td); parent.LoadingThread.Start(la); } }