output is shown while breakpoint otherwise not?
public void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Black);
开发者_StackOverflow中文版 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();
}
this function is working when i put a breakpoint in this function otherwise it is not showing the output of this function?...where is the problem i can't understand..?pls help with some idea or solution?
Here's my guess: you're having a race condition between the paint method and code which is supposed to populate keywords and eds collections. In other words paint is called before you have something inserted into these collections. When stepping through the code under debugger your collections loading routine have enough time to finish what it's supposed to be doing before foreach cycles kick in.
This is just a guess, you need to provide more of your code if you would want to have more intelligent answer.
精彩评论