Groups | Blog | Home
all groups > dotnet windows forms > june 2005 >

dotnet windows forms : DoEvents causes form to hang


kahwon t via DotNetMonster.com
6/21/2005 12:00:00 AM
SORRY I ACCIDENTALLY POSTED THIS IN THE WinForm Controls SECTION:

I can not figure out for the life of me why my app / form hangs afte I do a
show:

Me.Show()
While Not Done

System.Windows.Forms.Application.DoEvents()

End While

To test it, I threw a me.refresh in to see what was going on and when I ran
my code, I could work on the form for about 5 - 10 seconds before it hung.

Is there someone who might be able to help me?? this is an app that was
converted from vb6 to vb.net using the conversion tool.


--
Message posted via DotNetMonster.com
Jon Skeet [C# MVP]
6/21/2005 7:40:35 PM
[quoted text, click to view]

Well, whatever's actually happening, using Application.DoEvents like
that seems like a pretty bad idea to me. Why not just let the message
pump do its work in the normal way?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
kahwon t via DotNetMonster.com
6/21/2005 9:06:11 PM
That may be. The DoEvents is a holdover from the conversion. I was able to
get some relief by throwing in a thread.sleep(10) in the loop but when I go
to do a form.close now it appears to hang just like when I did a form.show.
It is becoming apparent to me that there is something I am missing here but
no knowledge article or book that I've looked in has been able to tell me
anything I need to fix this.......HELP!!!!!

[quoted text, click to view]


--
Message posted via DotNetMonster.com
Jon Skeet [C# MVP]
6/21/2005 10:20:29 PM
[quoted text, click to view]

It's definitely worth getting rid of the loop - it shouldn't be there
in the first place. You should just let the UI thread "do its thing"
and exit at the appropriate time.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
AddThis Social Bookmark Button