示例#1
0
        private static void Worker(Commons.SplineBox spline, Chart chart, ThreadPriority threadPriority)
        {
            ThreadTimeStopwatch threadTimeStopwatch = new ThreadTimeStopwatch();

            threadTimeStopwatch.Start();

            switch (Commons.SyncWay)
            {
            case Sync.Semaphore:
            {
                //c1 = getSemaphoreCount(_semaphore, 1);
                //Thread.Sleep(10);
                //WaitForSingleObject(_semaphore, 0xFFFFFFFF);
                //Thread.Sleep(10);
                //c2 = getSemaphoreCount(_semaphore, 1);
                MakeChanges(spline, chart, threadPriority, threadTimeStopwatch);
                ReleaseSemaphore(_semaphore, 1, (IntPtr)null);
                break;
            }

            case Sync.Mutex:
            {
                WaitForSingleObject(_mutex, 0xFFFFFFFF);
                MakeChanges(spline, chart, threadPriority, threadTimeStopwatch);
                ReleaseMutex(_mutex);
                break;
            }

            case Sync.Event:
            {
                WaitForSingleObject(_event, 0xFFFFFFFF);
                ResetEvent(_event);
                MakeChanges(spline, chart, threadPriority, threadTimeStopwatch);
                SetEvent(_event);
                break;
            }

            default:
            {
                Commons.EnterCriticalSection(Commons.LockObject);
                Commons.LeaveCriticalSection(Commons.LockObject);
                break;
            }
            }
            //log();

            /*
             * try
             * {
             *  makeChanges(spline, chart, threadPriority, threadTimeStopwatch);
             * }
             * finally
             * {
             *  Commons.WaitForSingleObject();
             *  Commons.SevEvent();
             * }*/
            //Console.WriteLine(c1);
            //Console.WriteLine(c2);
        }
示例#2
0
        private static void MakeChanges(Commons.SplineBox spline, Chart chart, ThreadPriority threadPriority,
                                        ThreadTimeStopwatch threadTimeStopwatch)
        {
            checkSplines(spline, chart);
            if (threadTimeStopwatch != null)
            {
                threadTimeStopwatch.Stop();

                WriteResultSummary(spline, threadPriority, threadTimeStopwatch.Elapsed);
            }
        }