private static void Process(string item, ServerSerializationDetails serverSerializationDetails) { Worker worker = new Worker(serverSerializationDetails.SourceServerDetails.ThreadName , item , serverSerializationDetails.SourceServerDetails.MessageDetails , serverSerializationDetails.SourceServerDetails , serverSerializationDetails.DestinationServerDetails , 1500 , 5); worker.ProcessFile(); }
private static void OnChanged(object source, FileSystemEventArgs e) { Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); WaitReady(e.FullPath); ServerSerializationDetails serverSerializationDetails = null; string path = e.FullPath; XmlSerializer serializer = new XmlSerializer(typeof(ServerSerializationDetails)); StreamReader reader = new StreamReader(path); serverSerializationDetails = (ServerSerializationDetails)serializer.Deserialize(reader); reader.Close(); //sequential approach //foreach (string item in serverSerializationDetails.SourceServerDetails.Files) //{ // Process(item, serverSerializationDetails); //} //parallel approach try { Parallel.ForEach(serverSerializationDetails.SourceServerDetails.Files.AsParallel(), new ParallelOptions { MaxDegreeOfParallelism = -1 }, item => Task.Factory.StartNew(() => Process(item, serverSerializationDetails)) ); } catch (Exception ex) { Console.WriteLine("=================" + ex.Message + "================="); } finally { File.Delete(e.FullPath); } }