输出是在断点处显示的,否则不是?

时间:2011-03-18 19:39:15

标签: .net winforms

 public void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        Pen p = new Pen(Color.Black);
        RadioButton r = new RadioButton();
        foreach (Keyword k4 in keywords)
        {
            e.Graphics.FillEllipse(Brushes.Blue, new Rectangle(100, k4.nodeno * 32, 10,    10));
        }
        int i = 0;
        foreach (edge e4 in eds)
        {
            if (e4.start + 1 == e4.end)
            {
                g.DrawLine(p, 100 + 4, e4.start * 32 + 10, 100 + 4, e4.end * 32);
                g.DrawLine(p, 100 + 8, e4.end * 32 - 8, 100 + 4, e4.end * 32);
                g.DrawLine(p, 100, e4.end * 32 - 8, 100 + 4, e4.end * 32);
            }
            else
            {
                int a = e4.start - e4.end;
                if (a < 0)
                {
                    a = -a;
                    g.DrawLine(p, 100 + 10, e4.start * 32 + 5, 150 + 5 + i, e4.start * 32 + 5);
                    g.DrawLine(p, 150 + 5 + i, e4.start * 32 + 5, 150 + 5 + i, e4.end * 32 + 5);
                    g.DrawLine(p, 150 + 5 + i, e4.end * 32 + 5, 100 + 10, e4.end * 32 + 5);
                    g.DrawLine(p, 100 + 10, e4.end * 32 + 5, 100 + 15, e4.end * 32);
                    g.DrawLine(p, 100 + 10, e4.end * 32 + 5, 100 + 15, e4.end * 32 + 10);
                }
                else
                {
                    g.DrawLine(p, 100, e4.start * 32 + 5, 50 - 5 - i, e4.start * 32 + 5);
                    g.DrawLine(p, 50 - 5 - i, e4.start * 32 + 5, 50 - 5 - i, e4.end * 32 + 5);
                    g.DrawLine(p, 50 - 5 - i, e4.end * 32 + 5, 100, e4.end * 32 + 5);
                    g.DrawLine(p, 100, e4.end * 32 + 5, 100 - 5, e4.end * 32);
                    g.DrawLine(p, 100, e4.end * 32 + 5, 100 - 5, e4.end * 32 + 10);
                }
                i = i + 10;
            }
        }
        p.Dispose();
    }

当我在这个函数中放置一个断点时,这个函数正在工作,否则它没有显示这个函数的输出?...我无法理解的问题在哪里...?请帮助一些想法或解决方案?

1 个答案:

答案 0 :(得分:0)

我的猜测是:你在 paint 方法和代码之间有一个race condition,它应该填充关键字 eds 系列。换句话说,在将某些内容插入这些集合之前调用paint。当在调试器下单步调试代码时,你的集合加载例程有足够的时间来完成它在foreach周期启动之前应该做的事情。

这只是一个猜测,如果你想要更聪明的答案,你需要提供更多的代码。