Solved

Multithreading Process in VB.Net

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

20 Experts available now in Live!

Get 1:1 Help Now