Bad DoEvents, Bad

  • Thread starter Thread starter Tim Johnson
  • Start date Start date
T

Tim Johnson

I wanted a "progress form" to monitor uploading a big batch of records via a
web service a few records at a time. In between batches I update a label
count field and issue Application.DoEvents(). In pseudo code it looks like
this:

lbl.Text = "0";
batchsize = 0;
for i=0 to bignum
{
getnext rec, add to table in dataset
batchsize++;

if batchsize = 50
{
cnt = webservice(dataset); //synchronous call
lbl.Text = cnt.ToString();
Application.DoEvents();
batchsize=0;
}
}

But about half to 3/4 of the time, the lbl.Text assignment seems to just
hang. In the debugger it goes in with F10, but it don't come out. In
runtime, debug or release, the loop never ends, presumably also stuck at the
same place.
I'm not doing this in form_Load, but in a routine triggered by the user
pushing a button, so all loading is settled down.

If I remove DoEvents, it works great every time. But of course I can't see
any progress.

How can I both see progress and make progress?
--

Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625
 
Interesting. I might have seen this before. Try calling lbl.Update() instead
of DoEvents
 
I'm on a single UI thread, but I found out what it was - any of the the code
would have worked fine but meanwhile there was another thread still
listening for and sometimes getting serial GPS data (using the GPSDotNet
SDK). Once I turned that off the screen updates occurred without a problem.

--

Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625
 
Back
Top