.net - MessageBox inside paint event high CPU -
i have custom listview, , wanted debug inside ondrawsubitem function displayng messagebox. expected gui freezing trying repaint item. weird thing cpu goes 100% when click subitem (after messagebox). can explain in loop has fallen this?
class listviewex : listview { public listviewex() { this.setstyle(controlstyles.allpaintinginwmpaint | controlstyles.optimizeddoublebuffer | controlstyles.resizeredraw, true); } protected override void ondrawcolumnheader(drawlistviewcolumnheadereventargs e) { e.drawdefault = true; } protected override void ondrawsubitem(drawlistviewsubitemeventargs e) { messagebox.show("test"); e.drawdefault = true; } }
edit
if same paint event of button have not high cpu (just repeated messagebox)
private void btntest_paint(object sender, painteventargs e) { messagebox.show("test"); }
i know it's not right display mbox inside paint events. i'm curious different behaviour in 2 examples.
like alex's comment suggests, should never use message boxes debugging aid when you're working ui code. cause kinds of problems , mask behavior you're trying debug.
a better solution involves either 1 or combination of following:
- breakpoints in strategic locations
- debug.assert test assumptions
- debug.writeline print diagnostics output/immedate window
Comments
Post a Comment