Exemplo n.º 1
0
        private void ThreadProc()
        {
            //DateTime last = DateTime.Now;
            //long sendMessageNumber = 0;
            //bool sleep1 = false;
            //int sendPerSec = 0;
            //int mod = 10;

            IntPtr handle = WinAPI.OpenThread(WinAPI.ThreadAccess.SET_INFORMATION | WinAPI.ThreadAccess.QUERY_INFORMATION, false,
                                              WinAPI.GetCurrentThreadId());

            WinAPI.SetThreadPriorityBoost(handle, true);

            WinAPI.CloseHandle(handle);

            while (true)
            {
                Event.WaitOne();

                //sendPerSec++;

                SCB[] scbs = _Listener.GetAllSCB();

                lock (LockObj)
                {
                    foreach (SCB scb in scbs)
                    {
                        if (this == _Listener.GetTask(scb))
                        {
                            scb.SendFromQueue();
                            //sendMessageNumber += scb.SendFromQueue();
                        }
                    }
                }

                Thread.Sleep(0);

                //DateTime now = DateTime.Now;

                //double elapseMilliseconds = (now - last).TotalMilliseconds;

                //if (elapseMilliseconds > 1000)
                //{
                //    double messagePerSecond = sendMessageNumber * 1000 / elapseMilliseconds;

                //    mod = ((int)(10000 / messagePerSecond) + 1) * 10;

                //    if (messagePerSecond > 1000)
                //    {
                //        sleep1 = true;
                //    }
                //    else
                //    {
                //        sleep1 = false;
                //    }

                //    sendPerSec = 0;
                //    sendMessageNumber = 0;
                //    last = DateTime.Now;
                //}

                //if (sleep1)
                //{
                //    if (sendPerSec % mod == 0)
                //    {
                //        Thread.Sleep(1);
                //    }
                //    else
                //    {
                //        Thread.Sleep(0);
                //    }
                //}
                //else
                //{
                //    Thread.Sleep(0);
                //}
            }
        }
Exemplo n.º 2
0
        private void ThreadProc()
        {
            //DateTime last = DateTime.Now;
            //long sendMessageNumber = 0;
            //bool sleep1 = false;
            //int sendPerSec = 0;
            //int mod = 10;



            while (true)
            {
                Event.WaitOne();

                //sendPerSec++;

                SCB[] scbs = _Listener.GetAllSCB();

                lock (LockObj)
                {
                    foreach (SCB scb in scbs)
                    {
                        if (this == _Listener.GetTask(scb))
                        {
                            scb.SendFromQueue();
                            //sendMessageNumber += scb.SendFromQueue();
                        }
                    }
                }

                Thread.Sleep(0);

                //DateTime now = DateTime.Now;

                //double elapseMilliseconds = (now - last).TotalMilliseconds;

                //if (elapseMilliseconds > 1000)
                //{
                //    double messagePerSecond = sendMessageNumber * 1000 / elapseMilliseconds;

                //    mod = ((int)(10000 / messagePerSecond) + 1) * 10;

                //    if (messagePerSecond > 1000)
                //    {
                //        sleep1 = true;
                //    }
                //    else
                //    {
                //        sleep1 = false;
                //    }

                //    sendPerSec = 0;
                //    sendMessageNumber = 0;
                //    last = DateTime.Now;
                //}

                //if (sleep1)
                //{
                //    if (sendPerSec % mod == 0)
                //    {
                //        Thread.Sleep(1);
                //    }
                //    else
                //    {
                //        Thread.Sleep(0);
                //    }
                //}
                //else
                //{
                //    Thread.Sleep(0);
                //}
            }
        }