Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"Refresh" method does not refresh

30 views
Skip to first unread message

Dom

unread,
Nov 8, 2012, 1:12:20 PM11/8/12
to
A program I have contains a Listview that keeps track of different
stages in the program. For example, a line in the listview may
indicate "starting to read the database", or "producing averages".
The method used to write these lines ends with:

lstview1.Refresh();
this.Refresh();

The second line seems like overkill to me, but I added it because the
first line did not work alone. In fact, the two lines together don't
work either. This confuses the users, who think the program is stuck.

How do I refresh things?

Dom

Jeff Johnson

unread,
Nov 8, 2012, 5:19:47 PM11/8/12
to
"Dom" <doliv...@gmail.com> wrote in message
news:dfe2065a-1968-4152...@c17g2000yqe.googlegroups.com...
Is the code that's processing the data running on the main thread? If so,
and it's a long-running process, that's probably the issue. Put that code in
a separate thread. You'll have to do a little bit of extra coding to update
the UI, since updates can only be performed by code on the main UI thread,
but there are a zillion examples of doing this on the 'Net. Just search for
".net update main ui from other thread invoke" and you should get more hits
than you can eat.


Registered User

unread,
Nov 8, 2012, 7:12:08 PM11/8/12
to
One possible solution would be to use data binding with an implementation of
INotifyPropertyChanged.
<http://msdn.microsoft.com/en-us/library/ms229614.aspx>

regards
A.G.

Dom

unread,
Nov 8, 2012, 8:53:04 PM11/8/12
to
Well,what I do is this ...

Open a DB connection
Process an SQL statement
Add item to list view and refresh

Process an SQL statement
Add item to list view and refresh

Etc.

Maybe what I should is ...

Open a DB connection
Process SQL statement
Close DB connection
Add item to list view and refresh

Open a DB connection, etc.

Would that change things?

Dom

Dom

unread,
Nov 9, 2012, 9:49:48 AM11/9/12
to
I got the answer. Instead of the "Refresh()" method, use
Application.DoEvents(). I suppose there is some danger here of firing
off unintended mouse clicks, but that's the price you pay.

Dom

Jeff Johnson

unread,
Nov 13, 2012, 11:15:06 AM11/13/12
to
"Dom" <doliv...@gmail.com> wrote in message
news:98b12a8e-6e35-49e7...@h9g2000yqd.googlegroups.com...
I'm surprised no one has chimed in with a rebuke on how bad a choice it is
to use DoEvents. I'd recommend you read up on it; it seems to be discouraged
in many circles.


Arne Vajhøj

unread,
Nov 19, 2012, 9:42:51 PM11/19/12
to
True.

It is in most cases a poor workaround for a bad design.

Much better to fix the design.

Those interested in the juicy details can Google:
application doevents evil

Arne

0 new messages