Esempio n. 1
0
        public void MultiThreadsMultiLogsTest()
        {
            Threads                 = new Thread[MaxThreads];
            ManualResetEvents       = new ManualResetEvent[MaxThreads];
            SmartLogGeneratorsArray = new SmartLogGenerator[MaxThreads];
            for (int threadIndex = 0; threadIndex < MaxThreads; threadIndex++)
            {
                string smartLoggerTestName = GetSmartLoggerTestName("MultiThreadsMultiLogsTest",
                                                                    threadIndex);
                SmartLoggerPerType <SmartLoggerTests> smartLoggerPerType = CreateSmartLoggerPerType(smartLoggerTestName);
                SmartLogGeneratorsArray[threadIndex] = CreateSmartLogGenerator(smartLoggerTestName,
                                                                               smartLoggerPerType);
                ManualResetEvents[threadIndex] = SmartLogGeneratorsArray[threadIndex].ManualResetEvent;
                Threads[threadIndex]           = CreateThread(SmartLogGeneratorsArray[threadIndex]);
                Threads[threadIndex].Start();
                Thread.Sleep(200);
            }

            // ReSharper disable once CoVariantArrayConversion
            WaitHandle.WaitAll(ManualResetEvents);

            for (int threadIndex = 0; threadIndex < MaxThreads; threadIndex++)
            {
                SmartLogGenerator smartLogGenerators = SmartLogGeneratorsArray[threadIndex];
                smartLogGenerators?.Dispose();
            }
        }
Esempio n. 2
0
        private static Thread CreateThread(SmartLogGenerator smartLogGenerator)
        {
            Thread thread = new Thread(smartLogGenerator.ThreadCallback);

            thread.Name = smartLogGenerator.Name;
            return(thread);
        }
Esempio n. 3
0
        private static SmartLogGenerator CreateSmartLogGenerator(string smartLoggerTestName,
                                                                 SmartLoggerPerType <SmartLoggerTests> smartLoggerPerType)
        {
            SmartLogGenerator smartLogGenerator = new SmartLogGenerator(smartLoggerTestName,
                                                                        new ManualResetEvent(false),
                                                                        smartLoggerPerType);

            return(smartLogGenerator);
        }
Esempio n. 4
0
        public void CurrentThreadTest()
        {
            string smartLoggerPerTypeName = GetSmartLoggerTestName("CurrentThreadTest",
                                                                   0);
            SmartLoggerPerType <SmartLoggerTests> smartLoggerPerType = CreateSmartLoggerPerType(smartLoggerPerTypeName);
            SmartLogGenerator smartLogGenerator = CreateSmartLogGenerator(smartLoggerPerTypeName,
                                                                          smartLoggerPerType);

            Assert.NotNull(smartLogGenerator);
            smartLogGenerator.ThreadCallback();
            smartLogGenerator.Dispose();
        }