Solved

Multithreading Process in VB.Net

Posted on 2004-09-29
8
326 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy/Clone an object. 9 32
More on Time zones in vb 2010 12 37
SQL syntax in VB.net 5 30
Help with AsEnumerable(), LINQ 4 23
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now