是否有可能提取我的代碼中的代碼部分,並讓它在多個線程中運行?多線程,DataReaders和批量插入...這個應用程序可以多線程?
該應用程序在複製數據從一個FoxPro數據庫到我們的SQL服務器通過網絡(文件是相當巨大的,因此批量複製需要增量發生......
它的工作原理,但我想顛簸起來的速度的比特。
1)通過任一具有I標記在多個線程中運行,或者作爲替代的部分中,
2)通過在數據行的每一列不循環,
我去了第二個選項...(更新下面的代碼)
CODE
private void BulkCopy(OleDbDataReader reader, string tableName, Table table)
{
if (Convert.ToBoolean(ConfigurationManager.AppSettings["CopyData"]))
{
Console.WriteLine(tableName + " BulkCopy Started.");
try
{
DataTable tbl = new DataTable();
foreach (Column col in table.Columns)
{
tbl.Columns.Add(col.Name, ConvertDataTypeToType(col.DataType));
}
int batch = 1;
int counter = 0;
DataRow tblRow = tbl.NewRow();
while (reader.Read())
{
counter++;
////This section changed
object[] obj = tblRow.ItemArray;
reader.GetValues(obj);
tblRow.ItemArray = obj;
////**********
tbl.LoadDataRow(tblRow.ItemArray, true);
if (counter == BulkInsertIncrement)
{
Console.WriteLine(tableName + " :: Batch >> " + batch);
counter = PerformInsert(tableName, tbl, batch);
batch++;
}
}
if (counter > 0)
{
Console.WriteLine(tableName + " :: Batch >> " + batch);
PerformInsert(tableName, tbl, counter);
}
tbl = null;
Console.WriteLine("BulkCopy Success!");
}
catch (Exception)
{
Console.WriteLine("BulkCopy Fail!");
}
finally
{
reader.Close();
reader.Dispose();
}
Console.WriteLine(tableName + " BulkCopy Ended.");
}
}
UPDATE 我去了第二個選項
我不知道,而同時內部(reader.Read())循環,我可以做下列。 I'T有助於大大提高應用程序的性能
while (reader.Read())
{
object[] obj = tblRow.ItemArray;
reader.GetValues(obj);
tblRow.ItemArray = obj;
tbl.LoadDataRow(tblRow.ItemArray, true);
}
我會嘗試高清所有的建議,爲興趣點,將你可以提供一個代碼示例,瞭解如何更改表鎖定類型,從c#..我現在是第一次聽說它,所以似乎有點太空時代:p(我會諮詢谷歌作爲好吧) – 2012-02-03 10:23:18