예제 #1
0
파일: Form1.cs 프로젝트: wm9947/gochat_team
        private void btn_end_Click(object sender, EventArgs e)
        {
            if (ServerTCPListner != null)
            {
                ServerTCPListner.Stop();
            }

            MessageBox.Show("server ended.!!");

            foreach (Socket SocketStart in HTSocketHolder.Values)
            {
                if (SocketStart.Connected)
                {
                    SocketStart.Close();
                }
            }

            foreach (Thread ThreadStart in HTThreadHolder.Values)
            {
                if (ThreadStart.IsAlive)
                {
                    ThreadStart.Abort();
                }
            }

            Application.Exit();
        }
예제 #2
0
        private void CreateJobsAndProcessInParallel(int numberOfThreads)
        {
            ConcurrentBag <int> threadIDs = new ConcurrentBag <int>();
            Stopwatch           watch     = new Stopwatch();

            watch.Start();
            ConcurrentQueue <Job>   queue     = new ConcurrentQueue <Job>();
            List <Thread>           list      = new List <Thread>();
            List <ManualResetEvent> eventList = new List <ManualResetEvent>();

            for (int i = 0; i < numberOfThreads; i++)
            {
                Thread t = new Thread(() => { DequeueAndProcess(queue); });
                list.Add(t);
                t.Start();
            }
            for (int i = 0; i < numberOfJobs; i++)
            {
                ManualResetEvent e = new ManualResetEvent(false);
                eventList.Add(e);
                ThreadStart t = new ThreadStart(() =>
                {
                    BubbleSort.DoBigBubbleSort(bubbleSize, threadIDs);
                });
                queue.Enqueue(new Job(t, e));
            }
            foreach (ManualResetEvent e in eventList)
            {
                e.WaitOne();
            }
            foreach (Thread t in list)
            {
                t.Abort();
            }

            watch.Stop();
            Console.WriteLine("Total elapsed (ms): " + watch.ElapsedMilliseconds);
        }