我已经完成BulkCopy of List using FastMember and Threading
以提高性能。
实际上,我需要对999999999
条记录进行批量处理,并且我为每个1000000
条记录设置了一个间隔,并Clearing the List
避免OutofMemory Exception
。16 Hours
整个过程类似于No records have been inserted
完成,现在,我的问题是:(nolock)
。在进行过程中,我已使用No Records
读取数据,我的查询显示数据,有时显示private void Btn_Start_Encrypting_Click(object sender, EventArgs e)
{
try
{
Btn_Start_Encrypting.Enabled = false;
Lbl_Msg1.Text = "Time Started : " + DateTime.Now.ToString();
DateTime StartTime = DateTime.Now;
#region List<CustomClass> with Random Numbers
Random rand = new Random();
Thread previousThread = null;
for (int i = 1; i <= 999999999; i++)
{
LstEncData.Add(new EncryptedData { MESSAGE_ID = rand.Next(1, 100), ENCRYPTED_DATA = EncryptDecrypt.Encrypt(i.ToString("D9")) });
if (i % 1000000 == 0)
{
LstEncData = LstEncData.OrderBy(p => p.MESSAGE_ID).ToList();
if (previousThread != null)
{
previousThread.Join();
}
List<EncryptedData> copyList = LstEncData.ToList();
previousThread = new Thread(() => BulkCopyList(copyList));
previousThread.Start();
LstEncData.Clear();
}
}
if (LstEncData.Count > 0)
{
if (previousThread != null)
{
previousThread.Join();
}
List<EncryptedData> copyList = LstEncData.ToList();
previousThread = new Thread(() => BulkCopyList(copyList));
previousThread.Start();
LstEncData.Clear();
}
previousThread.Join();
Lbl_Msg2.Text = "Time Ended : " + DateTime.Now.ToString();
DateTime EndTime = DateTime.Now;
TimeSpan duration = EndTime - StartTime;
Lbl_Msg3.Text = "Total Time Taken in Seconds : " + duration.TotalSeconds.ToString();
#endregion
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
Btn_Start_Encrypting.Enabled = true;
}
}
public void BulkCopyList(List<EncryptedData> Lst)
{
try
{
using (var bcp = new SqlBulkCopy(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]))
{
using (var reader = ObjectReader.Create(Lst, "ENCRYPTED_DATA"))
{
SqlBulkCopyColumnMapping mapEncryData = new SqlBulkCopyColumnMapping("ENCRYPTED_DATA", "ENCRYPTED_DATA");
bcp.ColumnMappings.Add(mapEncryData);
bcp.DestinationTableName = "EncryptedData1";
bcp.WriteToServer(reader);
}
}
}
catch (Exception ex)
{
}
}
。我认为数据已插入和删除。
原因,我这样说:如果我现在开始插入任何记录,身份栏显示数百万的非常大的数字。
所以,据我所知,我觉得已经插入和删除了记录。
我的代码:
{{1}}
我是否在线程(或)BulkCopy附近做错了什么?