Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SLOW SHOWING WINDOWS FORM

Posted on 2012-12-28
15
186 Views
Last Modified: 2013-01-04
Hi All,

I have experienced of slow showing windows form, because I have to load huge data to datagridview or other tasks.

I want to show the form first then after that loading data to gridview.

How could I solve this problem ?

Thank you.
0
Comment
Question by:emi_sastra
  • 7
  • 4
  • 3
  • +1
15 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38728745
"I want to show the form first then after that loading data to gridview."

Wire up the Shown() event of the Form, and place your code to load the grid in there.  You could also use the BackgroundWorker() control to do the query in the background...
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38728754
Hi Idle_Mind,

-Wire up the Shown() event of the Form
I don't get this ?

-You could also use the BackgroundWorker() control to do the query in the background...
Any sample of it ?

Thank you.
0
 
LVL 13

Expert Comment

by:themrrobert
ID: 38728763
Double click on the form and select the Shown() event. Put your code in there.  

(my code is just a sample you need to get the event from the IDE.
Public Sub Shown()
'Load Database code

End Sub


Here is how to use background worker: http://msdn.microsoft.com/en-us/library/cc221403%28v=vs.95%29.aspx
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38728765
Select the Form.  In the Properties Pane, bottom right by default, click on the "Lightning Bolt" icon.  Scroll down and find the "Shown" entry and double click to the right of it.
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 400 total points
ID: 38729252
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38730584
Hi Idle_Mind and  themrrobert,

There is no big difference with between shown and load event.

Thank you.
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 100 total points
ID: 38731140
You could also try forcing a repaint before the other loading code continues:
Me.Show()
Application.DoEvents()
' ... rest of the loading code ...

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731579
-You could also try forcing a repaint before the other loading code continues:
At what event ?

Thank you.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38731647
The Load() event...or wherever your code that loads the controls is.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731773
Yes, it improve showing form.

I would like also consider asynchronous data loading by emoreau.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731775
Hi emoreau,

Where to put the asynchronous data loading, at what event in order to make the data appear after form has shown?

Thank you.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 38732468
you can call the BeginExecuteXXX directly from the form_load event but I would create a LoadData method (called by the form_load event for that purpose.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38733855
-you can call the BeginExecuteXXX directly from the form_load event but I would create a LoadData method (called by the form_load event for that purpose.
- I am sorry, miss your point. BeginExecuteXXX  at load event but LoadData at load event also ?

Thank you.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 38734420
create a LoadData method. this method will contain the BeginExecuteXXX and everything to get the results.

Call this method from the form_load event
0
 
LVL 1

Author Closing Comment

by:emi_sastra
ID: 38745933
Hi All,

Thank you very much for your help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question