循环不必要地需要MessageBox,如果删除则会冻结

时间:2017-01-10 20:32:55

标签: c# loops messagebox

我有一个C#代码,当它运行时,它会在支持多行的文本框中将大约200个值提供给单独的行,但在中间提供一个消息框,我只是为了确保它正在提供正确的数据,现在冻结如果删除整个代码。我无法理解它的重要性,以前的文本框处理较重的负载而没有什么麻烦,但显然这需要一个短暂的休息或至少某种人类交互(幸运的是只按消息框上的OK按钮)所以我想知道是否有一个解决方案或解决方法就像一个类似的停止但不需要我的指导。只按200次以上的密钥来获取一组数据并不方便。

下面是代码,以防万一:

if (listBox3.SelectedIndex < 0 || listBox4.SelectedIndex < 0) {
    MessageBox.Show("Select the Chart Parameters(E.g.: BTC-USD)");
}

if (listBox4.GetItemText(listBox4.SelectedItem).Contains(listBox3.GetItemText(listBox3.SelectedItem))) {
    MessageBox.Show("Please select seperate pairs.(E.g.: NOT BTC-BTC but e.g.:BTC-USD)");
}
else
{
    string url = textBox8.Text + listBox3.GetItemText(listBox3.SelectedItem) + listBox4.GetItemText(listBox4.SelectedItem);
    MessageBox.Show(url);
    System.Net.WebClient client8 = new System.Net.WebClient();
    var html = client8.DownloadString(url);

    string s = html.Replace("[[", "[");
    string ss = s.Replace("]]", "]");

    textBox9.Text = ss;

    dynamic obj1 = JsonConvert.DeserializeObject(ss);     //ss is the data
    var timezz = (Int32)obj1.SelectToken("time");
    textBox11.Text = textBox11.Text + timezz;
    var data1m = (string)obj1.SelectToken("data1m");


    ICollection<string> matches =
      Regex.Matches(data1m, @"\[([^]]*)\]", RegexOptions.Multiline)
      .Cast<Match>()
      .Select(x => x.Groups[1].Value)
      .ToList();

    foreach (string match in matches) { textBox10.Text += Environment.NewLine + match; }

    for (int i = 1; i < textBox10.Lines.Length; i++)
    {
        string linebyline = textBox10.Lines[i];
        var resultString = Regex.Match(linebyline, @"\d+").Value;
        //uni_time = resultString;
        var yen = linebyline.Replace(resultString, string.Empty);
        MessageBox.Show(yen);                                        

        /////WHY DOES IT NEEDS TO BE STOPPED BY THIS MSGBOX INORDER2 EXECUTE THE WHOLE CODE???
        //////IF I REMOVE IT, IT FREEZES
        var resultz = yen.Substring(yen.LastIndexOf(',') + 1);
        //uni_vol = resultz;
        var ztring = yen.Replace(resultz, string.Empty);
        //MessageBox.Show(ztring);

        //Regex re = new Regex(@"\d+(\.\d{1,4})?");

        ICollection<string> mc = Regex.Matches(ztring, @"\d+(\.\d{1,4})?").Cast<Match>()
        .Select(x => x.Groups[0].Value)
        .ToList();

        foreach (string m in mc)
        {
            //MessageBox.Show(m);
            if (textBox13.Text == string.Empty) { textBox13.Text += m; }
            else
            {
                textBox13.Text += Environment.NewLine + m;
            }
        }
    }

}

0 个答案:

没有答案