在獲取數據的同時,似乎很長一段時間,我們無法在這段時間內完成另一項任務。我正在爲此使用BAckGroundWOrker。但似乎獲取所有數據後等待很長一段時間僅在該應用運行過程中出現細微等待很長時間從數據庫中獲取數據
private void btnExrtPDF_Click(object sender, RoutedEventArgs e)
{
btnExrtPDF.IsEnabled = false;
Collection.Clear();
long NoOfRecords = 10000;
long RecordsIcrease = 10000;
SaveFileDialog xsfd = new SaveFileDialog()
{
FileName = "Book1",
DefaultExt = ".xlsx",
Filter = "Excel Document|*.xlsx",
InitialDirectory = new System.IO.DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)).ToString()
};
Nullable<bool> result = xsfd.ShowDialog();
System.Data.DataTable batchFCSB = new System.Data.DataTable();
int row = 0;
if (result == true)
{
DetailReportFCBuySell = AlyexWCFService.DL.DLTTIn.FCBuySELL(transactionName, isDetails, Convert.ToDateTime(dateEdtStartDate.EditValue).Date, Convert.ToDateTime(dtpEditEndDate.EditValue).Date, Customerid, ProductID, branchID, NoOfRecords, PageIndex - 1, isBuy);
batchFCSB = DetailReportFCBuySell.ToDataTable();
Collection.Add(row, batchFCSB);
row = 1;
PageIndex++;
for (long k = NoOfRecords; k < DetailReportFCBuySell.FirstOrDefault().TotalRecords; k = +NoOfRecords)
{
new AlxServiceClient().Using(channel =>
{
DetailReportFCBuySell = new ObservableCollection<DLReports.FCBuySellDetail>();
DetailReportFCBuySell = AlyexWCFService.DL.DLTTIn.FCBuySELL(transactionName, isDetails, Convert.ToDateTime(dateEdtStartDate.EditValue).Date, Convert.ToDateTime(dtpEditEndDate.EditValue).Date, Customerid, ProductID, branchID, NoOfRecords, PageIndex - 1, isBuy);
batchFCSB = new System.Data.DataTable();
batchFCSB = DetailReportFCBuySell.ToDataTable();
Collection.Add(row, batchFCSB);
row++;
});
NoOfRecords = NoOfRecords + RecordsIcrease;
}
for (int k = 0; k < Collection.Keys.Count; k++)
{
string xlsxFile = string.Empty;
xlsxFile = System.IO.Path.GetTempFileName();
TableView temp = new TableView();
temp.DataContext = (Collection.Where(i => i.Key == k).FirstOrDefault().Value);
// ExportToXlsx(temp, xlsxFile);
}
}
m_oWorker.RunWorkerAsync();
}
嗨我可以知道的是後臺工作援引在哪裏?這看起來有點直接通過使用UI線程 –
m_oWorker.RunWorkerAsync(); –
這是在這裏面使用的。和我在構造函數 –