public void CancelLoad() { try { SelectCommand.Cancel(); thrSelect.Abort(); _dtLoaded.Dispose(); _dtLoaded = null; } catch (Exception) { } }
private void FillDataSet(object sender, DoWorkEventArgs e) { Log("Starting FillDataSet invoke..."); FillDataParam fillData = (FillDataParam)e.Argument; try { int startRecordIndex = fillData.StartRecord; int recordCount = 0; Log("Starting internal fill while loop..."); while (!fillData.DataReader.IsClosed && !_workerThread.CancellationPending) { bool fillCompleted = false; try { Log("Filling tables..."); if (fillData.DataSet != null) { recordCount = Fill(fillData.DataSet, fillData.SourceTableName, fillData.DataReader, 0, PageSize); } else { recordCount = Fill(fillData.DataTables, fillData.DataReader, 0, PageSize); } Log($"Tables filled. Record count={recordCount}"); fillCompleted = recordCount == 0 || recordCount != PageSize; Log($"Fill completed boolean={fillCompleted}"); if (FillDataChunk != null) { FillDataChunk(fillData, startRecordIndex, recordCount); if (fillData.Cancel) { _workerThread.CancelAsync(); SelectCommand.Cancel(); fillCompleted = true; } } startRecordIndex += recordCount; Log($"Next start instance: {startRecordIndex}"); } catch (Exception ex) { fillCompleted = true; throw new InvalidOperationException("Failed to fill data chunk.", ex); } finally { Log($"Closing resources."); if (fillData.DataReader != null && fillCompleted) { fillData.DataReader.Close(); } if (SelectCommand.Connection != null) { SelectCommand.Connection.Close(); } } } IsExecuting = false; } catch (Exception ex) { fillData.Error = ex; } finally { e.Result = fillData; } }