Example #1
0
        static void task2()
        {
            //Table lt = new Table();
            //lock (lok2)
            //{
            //    using (context2 = new MPCEntities())
            //    {
            //        lt = context2.Table.FirstOrDefault(p => p.State == 1);
            //        if (lt != null)
            //        {
            //            lt.State = 2;
            //            Thread th = new Thread(WriteFile);
            //            th.Start(lt);
            //            context2.SaveChanges();
            //        }
            //        else
            //            return;
            //    }
            //}

            List<Table> lts = new List<Table>();
            lock (lok2)
            {
                using (context2 = new MPCEntities())
                {
                    lts = context2.Table.Where(p => p.State == 1).ToList();
                    if (lts != null)
                    {
                        foreach (var lt in lts)
                        {
                            lt.State = 2;
                            Thread th = new Thread(WriteFile);
                            th.Start(lt);

                        }
                    }
                    else
                        return;
                    context2.SaveChanges();
                }

            }
        }
Example #2
0
 static void task1()
 {
     string tick;
     using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client()) tick = client.getTicks();
        // Thread.Sleep(15000);
     lock (lok1)
     {
         using (context = new MPCEntities())
         {
             context.Table.Add(new Table() { Data = tick, State = 1 });
             context.SaveChanges();
         }
     }
 }