Solved

Multithreading Process in VB.Net

Posted on 2004-09-29
8
327 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
8 Comments
 
LVL 85

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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