コード例 #1
0
        private void ProcessRecords(object state)
        {
            //cast state object
            var trueState = state as Tuple <ConcurrentSqlExtractor, ConcurrentFlatFileWriter, string>;
            var reader    = trueState.Item1;
            var writer    = trueState.Item2;
            var delim     = trueState.Item3;
            //make stringbuilder
            StringBuilder builder = new StringBuilder();

            OutputToConsoleAndLog($"Thread {Thread.CurrentThread.Name} is starting execution");
            object[] SourceData;
            int      progress = 0;

            while (reader.TryExtractRecord(out SourceData))
            {
                builder.Clear();
                int objCount = SourceData.Count();
                //append items including delimiter
                for (int i = 0; i < objCount - 1; i++)
                {
                    builder.Append(SourceData[i].ToString());
                    builder.Append(delim);
                }
                //append final item w/o delimiter
                builder.Append(SourceData[objCount - 1].ToString());
                writer.WriteLine(builder.ToString());
                if (++progress % 1000 == 0)
                {
                    OnLinesWritten(Thread.CurrentThread.Name, 1000);
                }
            }
            OnLinesWritten(Thread.CurrentThread.Name, 1000);
        }