Form.Refresh during intensive processing

G

Guest

Hi,

I've been struggling to get my form to refresh during the loading of large
objects on startup of my application.

I'm trying to get an image sequence to cycle on a splash screen during this
loading as the whole process takes ~1 minute.

The object loading code is in the Form_Load event and any time I call
this.Refresh() in this method it works as expected. The problem is that one
of my objects is extremely large (takes >30 seconds to load from the
database) so I'm trying to get an "I'm still alive" indicator to move during
the loading of this object. The object itself is loaded into a singleton so I
can't pass a delegate or have the form attach to an EventHandler (which I
would raise an event against inside the object loading code to indicate
progress).

The Windows.Forms.Timer seems to be utterly useless (doesn't fire at all
until the Load event is complete) and I have tried the System.Threading.Timer
which fires fine but the this.Refresh() call has absolutely no effect on the
display.

The "I'm still alive" image sequence is in a 'View' control which has an
ActiveIncrement method that changes which image is displayed. I tried having
an Event raised in this method that the Form attaches to and calls
Form.Refresh(). This works fine when the ActiveIncrement is called in the
Form_Load event code but does not work when it is called in the
Threading.Timer code. Note: the this.Refresh() is called every time it just
has no visual effect when called in the Timer code.

What the hell is going on!!!??!!!!!?!?!?! Is there some sort of threading
issue that is preventing the form from invalidating? Does anyone have a
method for periodically updating the form display during start up code?

Cheers,

Peter Mauger
 
G

Guest

Just as an update... I read Daniel Moth's blog re Control.Invoke and
attempted to implement it. The GUI thread doesn't seem to be responding to
the Form.Invoke until after the load event has completed... I couldn't work
out how to create a direct delegate to the Refresh method so I created a
simple EventHandler delegate that calls the Refresh method. The Invoke didn't
result in the method being called.
 
D

Daniel Moth

You mean this:
http://www.danielmoth.com/Blog/2004/10/invoke-cf-and-full-fx.html

As a rule I let my forms load while showing the busy cursor. That is
animation enough... anything more and all you achieve is delaying the
loading even further...
attempted to implement it. The GUI thread doesn't seem to be responding to
the Form.Invoke until after the load event has completed... I couldn't
work
I have not experienced control.invoke not working until the form_load event
has finished on the compact framework... It is true on the full framework
though since it needs a valid handle so on the desktop you would get an
exception if you tried invoke before a form has been loaded and thus has a
handle... The CF is slightly different when it comes to handle creation and
you say you don't get an exception so that sounds right. I suspect the
reason it waits for Load event to complete is because there can only be one
method running on a thread at any one time (in this case the UI thread). So
since form_load was there first, anything else is queued. In other words,
control.invoke marshals execution to the UI thread *when* the UI thread is
idle (until that time it is blocked).
simple EventHandler delegate that calls the Refresh method. The Invoke
didn't
result in the method being called.
This one is as expected in v1.0 To quote my blog entry:
1. You cannot pass any delegate you want to Invoke; rather, you can only use
the EventHandler. So, if you were hoping on using the efficient
MethodInvoker or one of your own, forget about it.

So again.. I would stick to the default cursor animation (Cursor.Current =
Cursors.WaitCursor).. If you really need to show your own, use the
Forms.Timer... The fact that it doesn't update instantly is a clue the UI
thread is busy enough.. Alternatively, redesign your app so it uses load on
demand and doesn't create the universe on startup...

Cheers
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top