I'm attempting to write a desktop application that will build and post multiple files for a list of clients. There are thousands of clients and the data that will be written to these files can be large thus the desire to convert this process to write these files in parallel to see what speed increases can be made to this process. I currently have this process looping through the list of clients and building the reports for each client and posting them to the corresponding output directories. My main question would be are the variables, objects, references kept separate in each individual thread as not to cause a conflict with each other.
Would there be an issue with the StreamWriter variable being named the same for each thread?
Example:
Parallel.ForEach(dt_sites.AsEnumerable(), sites_dr =>
{
site_nbr = Convert.ToInt32(sites_dr["sitenbr"]);
site_nm = ((string)(sites_dr["sitename"])).Trim();
site_dir = ((string)(sites_dr["postpath"])).Trim();
site_work_dir = Path.Combine("c:\work\", site_nbr.ToString().PadLeft(5, '0'));
cls_build_file(dr_clms_data, p_site_nbr, site_work_dir);
});
public static void cls_build_file(DataRow [] p_clms_dr, int p_site_nbr, string p_work_dir)
{
StreamWriter sw = new StreamWriter(Path.Combine(p_work_dir, "test.txt"));
sw.Write("test");
sw.Close();
sw.Dispose();
}