Esempio n. 1
0
        public void WriteNumbersToFile()
        {
            Console.WriteLine("Begin Logging to File");
            var         generator = new NumberGenerator();
            IFileLogger myLogger  = null;

            foreach (long integer in generator.Integers())
            {
                Console.Write(".");
                myLogger = _fileLoggerFactory.Create();
                myLogger.WriteLineToFile("Getting next number...");
                myLogger.WriteLineToFile("Logged Number: " + integer);

                // this is inefficient...
                if (_fileLoggerFactory is InstanceFileLoggerFactory)
                {
                    myLogger.CloseFile();
                }

                if (integer >= _maxIntegerToWrite)
                {
                    break;
                }
            }
            myLogger.CloseFile();
            Console.WriteLine();
        }
Esempio n. 2
0
        public void WriteNumbersToFile()
        {
            Console.WriteLine("Begin Logging to File");
            var         generator = new NumberGenerator();
            IFileLogger myLogger  = null;

            Action <int> logToFile = i =>
            {
                Console.Write(".");
                myLogger = _fileLoggerFactory.Create();
                myLogger.WriteLineToFile("Getting next number...");
                myLogger.WriteLineToFile("Logged Number: " + i);
            };

            Parallel.For(0, _maxIntegerToWrite, logToFile);

            myLogger.CloseFile();
            Console.WriteLine();
        }