Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Parallel.For error

$
0
0
I have made my program parallel with following code but i am getting following error
private void button2_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
            {
                label2.Text = saveFileDialog1.FileName;
                string[] value;
                string file = openFileDialog1.FileName;
                string[] readText = File.ReadAllLines(file);
                string[] writetext = (string[]) readText.Clone(); 
                //for(int i=0;i< readText.Length;i++)
                //{
                   Parallel.For(0, readText.Length, i =>
                   { 
                    if ((!readText[i].Contains("#")) && (!(readText[i].Length ==0 )))
                    {
                        string[] fields = readText[i].Split('\t'); //<-- change field separator here & split fields
                        for (int j = 0; j < fields.Length; j++)
                        {
                            value = fields[j].Split(new char[] { ':' }, 2);
                            if (value[0].ToString() == "Message")
                            {
                                if (value[1].ToString().Trim() != "MlogWrite")
                                {
                                    string Decoded = sample(fields[7].Trim(), fields[8].Trim(), fields[9].Trim());
                                    string temp = Decoded.Trim(new char[] { '\n' });
                                    writetext[i] = writetext[i] + "\tDecoded Payload(" + Decoded + ")";
                                 }
                            }
                        }
                    }
                //}
                 });

                File.WriteAllLines(@label2.Text, writetext);
            }
        }
    }
as i am newbie to parallel.for. please do somelook look at my code and comment and correct me .

Girish


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>