Solved

Multithreading Process in VB.Net

Posted on 2004-09-29
8
332 Views
Last Modified: 2008-03-04
Hi all!

When my form loads, i need fill a dataset with some data from a oracle database. The server needs about 30 secs to return the results that i will use to fill my dataset.

But, i don't whan't to wait for the filling process end to be able to work with my form, so, i'm thinking using a thread to the fill process, and call this thread from my form_load event.

I created a class that will be used to fill the dataset. This class has the method called filldts.
When the form_load event is called, the thread is called and started, but, my form doesn't appear until the thread ends.

Does anyvody can show me a example of how implement this?

Thanks all!
0
Comment
Question by:regisdaniel
[X]
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
8 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 64 total points
ID: 12184247
You just need to make the form show and refresh itself before starting your thread:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim delayedLoadTime As DateTime

        Me.Show()    ' force the form to show and update itselft
        Me.Refresh() ' before going into the long process

        delayedLoadTime = DateTime.Now().AddSeconds(10)
        While DateTime.Now < delayedLoadTime
            ' man this form loads slow...
        End While
    End Sub

~IM
0
 
LVL 2

Expert Comment

by:GohdanTheMoblin
ID: 12184316
How are you starting the thread, and how does it interact with the for?.  Threads aren't my specialty, but if the dataset is already bound to a control like a DataGrid, this could be part of the problem.  If this is the case, try binding the control after the thread has completed.
0
 
LVL 14

Assisted Solution

by:ptakja
ptakja earned 62 total points
ID: 12186134
I suggest downloading & installing the 101 VB.Net Code Samples from the MSDN website:

http://www.microsoft.com/downloads/details.aspx?FamilyId=08E3D5F8-033D-420B-A3B1-3074505C03F3&displaylang=en

It covers a bunch of stuff, one part of which is threading.
0
 
LVL 19

Assisted Solution

by:arif_eqbal
arif_eqbal earned 62 total points
ID: 12187581
See if you have called a new thread and filling the data in this thread your form will show parallelly but the issue is Rendering form on screen takes its time so the main thread should be given sufficient time to show the form. So you can set the Priority of the new thread to say BelowNormal

Thread1.Priority=Threading.ThreadPriority.BelowNormal

May be it can help
0
 
LVL 8

Assisted Solution

by:wguerram
wguerram earned 62 total points
ID: 12190202
After showing the form call:

dim f as new form1
f.Show
f.Refresh
Application.DoEvents
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

738 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