3

私のプログラムでは、タスク並列ライブラリを使用してプロセスの時間を短縮しています。このコードを使用して作業を行います。

Task[] tasks = new Task[10]
{
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 1 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 2 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 3 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 4 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 5 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 6 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 7 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 8 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 9 , (e.Argument as string[])[1])),
    Task.Factory.StartNew(() => DoFiles(fullNum,NotFullNum, 10, (e.Argument as string[])[1]))
};

Task.WaitAll(tasks);

DoFiles() メソッドはいくつかのファイルを処理し、データベース内のファイルに単語を挿入します。すべてのタスクはいくつかのファイルを処理します。このコードを使用してデータベースに挿入します。

SqlBulkCopy sbc = new SqlBulkCopy(clsGlobal.cnTashih);
sbc.DestinationTableName = "tblListTekrari_3";
sbc.BulkCopyTimeout = 0;
sbc.WriteToServer(dtT);
sbc.Close();

プログラムを実行すると、次のエラーが発生することがあります。

Cannot access destination table 'tblListTekrari_3'.

System.Data

The request failed to run because the batch is aborted, this can be caused by abort signal sent from client, or another request is running in the same session, which makes the session busy.

at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternal()
at System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServer(Int32 columnCount)
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table, DataRowState rowState)
at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table)
at tashih.frmStart.DoFiles(Int32 countFull, Int32 NotCountFull, Int32 part, String ProjectID)

誰でも私を助けることができますか?

4

1 に答える 1