private void BulkExcute() { if (!ls.bRegOK) return; try { using (DataClasses1DataContext mess = new DataClasses1DataContext(streamType.LocalConnString)) { minFileNum = mess.IP_stream.Min(e => e.FileNum).Value; maxFileNum = mess.IP_stream.Max(e => e.FileNum).Value + 1; } // MessageBox.Show(minFileNum.ToString() + " - " + maxFileNum.ToString()); //DualTests dt = new DualTests(); //dt.Show(); dt.Focus(); dualTests1.Location = new Point(this.Width / 10, this.Height / 3); dualTests1.Show(); dualTests1.Focus(); handleTable h = new handleTable(); toolStripStatusLabel1.Text = h.AlterPrimaryKey(); //case"InitImeiCiTypeTable": //toolStripStatusLabel1.Text = h.InitImeiCiTypeTable(); //case"InitMlocationTable": //toolStripStatusLabel1.Text = h.InitMlocationTable(); //case"InsertImeiType": toolStripStatusLabel2.Text = "imei......"; Application.DoEvents(); imeiTypeClass _imeiTypeClass = new imeiTypeClass(true); Parallel.For(minFileNum, maxFileNum, i => { _imeiTypeClass.InsertImeiType(_imeiTypeClass, i); }); Thread.Sleep(1); GC.Collect(); GC.Collect(); Application.DoEvents(); dualTests1.Focus(); //case"InsertCiType": toolStripStatusLabel2.Text = "ci......"; Application.DoEvents(); ciType _ciType = new ciType(true); Parallel.For(minFileNum, maxFileNum, i => { _ciType.InsertCiType(_ciType, i); }); Thread.Sleep(1); GC.Collect(); GC.Collect(); Application.DoEvents(); dualTests1.Focus(); //case"UpdateImeiType": toolStripStatusLabel2.Text = "imei update......"; Application.DoEvents(); imeiTypeClass _imeiTypeClass_false = new imeiTypeClass(false); Task t2 = new Task(() => { _imeiTypeClass_false.UpdateImeiType(); }); t2.Start(); Thread.Sleep(1); GC.Collect(); GC.Collect(); Application.DoEvents(); dualTests1.Focus(); //case"InsertResultTable": toolStripStatusLabel2.Text = "locating......"; Application.DoEvents(); mLocatingConvert ml = new mLocatingConvert(); Parallel.For(minFileNum, maxFileNum, i => { ml.SendOrders(ml, i); }); Thread.Sleep(1); GC.Collect(); GC.Collect(); Application.DoEvents(); dualTests1.Focus(); dualTests1.Hide(); //dualTests1.Dispose(); using (DataClasses1DataContext mess = new DataClasses1DataContext(streamType.LocalConnString)) { mess.CommandTimeout = 0; string a=mess.mLocatingType.Max(e => e.mLocatingType_id).ToString(); string b = mess.IP_stream.Sum(e => e.IPstream).Value.ToString(); toolStripStatusLabel2.Text = "complete......"+ a + "/" + b; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void SendOrders(mLocatingConvert ml, int filenum) { //Stopwatch sw = new Stopwatch(); //sw.Start(); using (SqlConnection con = new SqlConnection(streamType.LocalConnString)) { con.Open(); using (SqlTransaction tran = con.BeginTransaction()) { var newOrders = ml.mLocatingTypeLength(filenum); SqlBulkCopy bc = new SqlBulkCopy(con, //SqlBulkCopyOptions.CheckConstraints | //SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.KeepNulls, tran); bc.BulkCopyTimeout = 36000; bc.BatchSize = 10000; bc.DestinationTableName = "mLocatingType"; bc.WriteToServer(newOrders.AsDataReader()); tran.Commit(); } con.Close(); } Thread.Sleep(1); GC.Collect(); GC.Collect(); Application.DoEvents(); //sw.Stop(); //localdbageBox.Show(sw.Elapsed.TotalSeconds.ToString()); //using (DataClasses1DataContext localdb = new DataClasses1DataContext(streamType.LocalConnString)) // filenum = localdb.mLocatingType.Count(); //MessageBox.Show(filenum.ToString() + "---" + sw.Elapsed.TotalSeconds.ToString() + "---"); }