Multithread Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rusdyrip
    New Member
    • Jan 2008
    • 29

    Multithread Problem

    hi

    i am trying to make simple application to learn multi thread

    but i have problem to make it

    the problem is the form can't respond while loading data

    i want to make it loading,but i can open new form

    thx

    this my sample


    [CODE=vbnet]
    Imports System.Componen tModel
    Imports System.Threadin g

    Public Class Form1
    Dim othread(10) As Thread
    Private Sub Startprocess(By Val state As Object)
    If Me.InvokeRequir ed Then
    Me.Invoke(New MethodInvoker(A ddressOf Fill))
    Else
    Fill()
    End If
    End Sub
    Private Sub Fill()
    For counter As Integer = 0 To 2000
    If counter = 2000 Then Label1.Text = "THE FORM IS FINISH"
    Debug.WriteLine (counter)
    Next
    End Sub

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
    System.Threadin g.ThreadPool.Qu eueUserWorkItem (New System.Threadin g.WaitCallback( AddressOf Startprocess))
    Label1.Text = "THE FORM IS LOADING"
    End Sub

    Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click
    Form2.Show()
    End Sub

    End Class[/CODE]
    Last edited by debasisdas; Feb 8 '08, 05:13 AM. Reason: added code=vbnet tags
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by rusdyrip
    hi
    i am trying to make simple application to learn multi thread
    but i have problem to make it
    the problem is the form can't respond while loading data
    i want to make it loading,but i can open new form
    thx
    Have you tried using DoEvents?
    It might not help, since you use only one line to load the data. But give it a try, the chances are good. ^.^

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Subscribing .

      Comment

      • rusdyrip
        New Member
        • Jan 2008
        • 29

        #4
        if i use do event i scared that it will make application slow,
        cause i call this do event every loop data

        i read some artikel ,
        it like use something like x process communication
        but i don't know how to use it

        Comment

        Working...