Exemple #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("-----------------------start");
            int             EventCount = 0, numOfThreads = 0;
            MySqlRepository mySql = new MySqlRepository();

            EventCount   = mySql.GetTabelCount();
            numOfThreads = EventCount / pagenum + 1;
            Console.WriteLine($"{numOfThreads},{EventCount}");

            int maxConcurrency = 10;

            using (concurrencySemaphore = new SemaphoreSlim(maxConcurrency))
            {
                List <Task> ts = new List <Task>();
                for (int i = 0; i < EventCount; i += pagenum)
                {
                    concurrencySemaphore.Wait();
                    Task t = Task.Factory.StartNew(TaskRun, i);
                    ts.Add(t);
                }
                Task.WaitAll(ts.ToArray());
            }

            Console.WriteLine("\n-----------------------end");
            Console.Read();
        }
Exemple #2
0
 private static void TaskRun(object i)
 {
     try
     {
         MySqlRepository mySql = new MySqlRepository();
         Console.WriteLine($"({i}),{Thread.CurrentThread.ManagedThreadId}/{Process.GetCurrentProcess().Threads.Count} ");
         var evetb = mySql.GetEvents((int)i, pagenum);
         //MongoDBRepository mongo = new MongoDBRepository();
         //mongo.EntryEvent(evetb.ToList());
     }
     finally
     {
         concurrencySemaphore.Release();
     }
 }