Пример #1
0
        private void DataToDB()
        {
            List <Task> tasks = new List <Task>();

            while (!readFinished || (QueueDUTs.Count > 0))
            {
                if (QueueDUTs.Count != 0)
                {
                    DUT_Str dut = QueueDUTs.Dequeue();

                    Task t = new Task(() =>
                    {
                        //connect to db
                        MySQLUtil db = new MySQLUtil();
                        db.connect();

                        if (db.insert_into_table(dut))
                        {
                            string str = String.Format("ADD: {0,-20} {1, -6} {2, -10} {3, -5} {4, -20}", dut.SerailNumber, dut.ErrorCode, dut.PartType, dut.IDDValue, dut.TestTime);
                            Trace.WriteLine(str);

                            //File.Move(logsFilePath.ToString() + @"\" + file.Name, directoryInfoAchieved.ToString() + @"\" + file.Name);
                            //System.Threading.Thread.Sleep(100);
                        }
                        else
                        {
                            Trace.WriteLine("Insert Into Table Error: " + db.LastError);
                        }

                        //disconnet
                        db.disconnect();
                    });

                    t.Start();
                    tasks.Add(t);
                }
            }

            Task.WaitAll(tasks.ToArray());
        }
Пример #2
0
        private void DataToDB()
        {
            
            List<Task> tasks = new List<Task>();

            while (!readFinished || (QueueDUTs.Count > 0))
            {
                if (QueueDUTs.Count != 0)
                {
                    DUT_Str dut = QueueDUTs.Dequeue();

                    Task t = new Task(() =>
                        {
                            //connect to db
                            MySQLUtil db = new MySQLUtil();
                            db.connect();

                            if (db.insert_into_table(dut))
                            {
                                string str = String.Format("ADD: {0,-20} {1, -6} {2, -10} {3, -5} {4, -20}", dut.SerailNumber, dut.ErrorCode, dut.PartType, dut.IDDValue, dut.TestTime);
                                Trace.WriteLine(str);

                                //File.Move(logsFilePath.ToString() + @"\" + file.Name, directoryInfoAchieved.ToString() + @"\" + file.Name);
                                //System.Threading.Thread.Sleep(100);
                            }
                            else
                            {
                                Trace.WriteLine("Insert Into Table Error: " + db.LastError);
                            }

                            //disconnet
                            db.disconnect();
                        });

                    t.Start();
                    tasks.Add(t);
                }
            }

            Task.WaitAll(tasks.ToArray());

        }