R – .NET Compact Framework: how to ensure form is visible before running code

compact-frameworkperformanceuser interfacewinforms

We've got a Model-View-Presenter setup with our .NET Compact Framework app. A standard CF Form is implementing the view interface, and passed into the constructor of the presenter. the presenter tells the form to show itself by calling view.Run(); the view then does a Show() on itself, and the presenter takes over again, loading up data and populating it into the view.

Problem is that the view does not finishing showing itself before control is returned to the presenter. since the presenter code blocks for a few seconds while loading data, the effect is that the form is not visible for a few seconds. it's not until after the presenter finishes it's data load that the form becomes visible, even though the form called Show() on itself before the presenter started its data loading.

In a standard windows environment, i could use the .Shown event on the form… but compact framework doesn't have this, and I can't find an equivalent.

Does anyone know of an even, a pinvoke, or some other way to get my form to be fully visible before kicking off some code on the presenter? at this point, i'd be ok with the form calling to the presenter and telling the presenter to start it's data load.

FYI – we're trying to avoid multi-threading, to cut down on complexity and resource usage.

Best Answer

If your key problem is that the form won't paint before your presenter data loading methods are completed, and you have a call to this.Show() in your Form_Load, try putting Application.DoEvents() directly after this.Show() to force/allow the form to paint.

protected void Form_Load(blah blah blah)
{
   this.Show();
   Application.DoEvents();

   ... data loading methods ...
}
Related Topic