public void ThreadMain() { FileWriter writer = new LargeFileWriter(this.des, FileMode.Create); var count = 0; foreach (var line in this.lines) { if ((++count) % 1000 == 0) { Console.WriteLine(Thread.CurrentThread.Name + " has processed " + count); } try { var feature = ExtractBayesFeature(line); writer.Cache(feature.first); var dic = feature.second; foreach (var field in dic.Keys) { writer.Cache("\t" + field + ":{"); var values = dic[field]; if (values is IEnumerable && !(values is string)) { var begin = true; foreach (var value in (IEnumerable)values) { if (begin) { writer.Cache(value); begin = false; } else { writer.Cache("," + value); } } writer.Cache("}"); } else { writer.Cache(values + "}"); } } writer.Cache("\r"); writer.WriteCache(); } catch (Exception e) { Console.WriteLine(line); Console.WriteLine(e.Message); writer.ClearCache(); } } writer.Close(); }