Using C#, I want to generate 1,000,000 files from DB, each record in separate file. What is the best way to generate this files in minimum time?
Here is my code without threading :
AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); // to calculate the execution time in case of using threading
    SqlCommand cmd = new SqlCommand(@"select top 1000000 p1+','+p2+','+p3+','+p4 as line from lines  ", con);
    con.Open();
    var rdr = cmd.ExecuteReader();
    int i = 0;
    while (rdr.Read())
    {
        string line = rdr.Getring(0);
        string filename = String.Format("file{0}.txt", ++i);
        File.WriteAllText(filename, line);
    }
    rdr.Close();
    con.Close();