Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. threading impliment

threading impliment

Scheduled Pinned Locked Moved Visual Basic
questioncsharpcomhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael Hulak
    wrote on last edited by
    #1

    I have an application which is near complete, but I never thought it would get this big or desired. The application reads a folder with files in it for user settings, then waits for user input. When input is started, it does specific searches online. When it is doing these searches, the application appears frozen until it finds what the user was looking for and prompts the user for input. I have tried a few ways to get threading into this, but everytime I get the problem similar to the following. Cross-thread operation not valid: Control 'ProgressBar1' accessed from a thread other than the thread it was created on. I tried starting a new thread within the application following http://www.codeproject.com/Articles/15861/How-to-solve-quot-Cross-thread-operation-not-valid and I still get the same problem. How can I turn my single threaded application into a multiple threaded application? I am using vb.net 2008

    D L 2 Replies Last reply
    0
    • M Michael Hulak

      I have an application which is near complete, but I never thought it would get this big or desired. The application reads a folder with files in it for user settings, then waits for user input. When input is started, it does specific searches online. When it is doing these searches, the application appears frozen until it finds what the user was looking for and prompts the user for input. I have tried a few ways to get threading into this, but everytime I get the problem similar to the following. Cross-thread operation not valid: Control 'ProgressBar1' accessed from a thread other than the thread it was created on. I tried starting a new thread within the application following http://www.codeproject.com/Articles/15861/How-to-solve-quot-Cross-thread-operation-not-valid and I still get the same problem. How can I turn my single threaded application into a multiple threaded application? I am using vb.net 2008

      D Offline
      D Offline
      Dineshshp
      wrote on last edited by
      #2

      A thread is a new process started by u and it can not access controls of thread who create it. but the child thread can return data to parent thread. error "Cross-thread operation not valid: Control 'ProgressBar1' accessed from a thread other than the thread it was created on" thrown by your code is an example of it. Solution: you can use BackgroundWorker class to reduce your problem. it will start a new thread and doesn't hang your application while searching and it can also return data to your application after completion of it's execution. if you can work according to my suggesion then OK otherwise tell me, i will give an example code that will solve your problem.

      1 Reply Last reply
      0
      • M Michael Hulak

        I have an application which is near complete, but I never thought it would get this big or desired. The application reads a folder with files in it for user settings, then waits for user input. When input is started, it does specific searches online. When it is doing these searches, the application appears frozen until it finds what the user was looking for and prompts the user for input. I have tried a few ways to get threading into this, but everytime I get the problem similar to the following. Cross-thread operation not valid: Control 'ProgressBar1' accessed from a thread other than the thread it was created on. I tried starting a new thread within the application following http://www.codeproject.com/Articles/15861/How-to-solve-quot-Cross-thread-operation-not-valid and I still get the same problem. How can I turn my single threaded application into a multiple threaded application? I am using vb.net 2008

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        The Invoke pattern;

        Imports System.Threading

        Public Class Form1
        Dim MyNewThread As Thread

        Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        
            'create the thread 
            MyNewThread = New Thread(AddressOf MyThread.MyThreadExecute)
            MyThread.ThatForm = Me
            'start the thread
            MyNewThread.Start()
        End Sub
        
        Public Sub SetProgress(ByVal What As String)
            If InvokeRequired Then
                Invoke(New Action(Of String)(AddressOf SetProgress), New Object() {What})
                Return
            End If
        
            Label1.Text = What
        End Sub
        

        End Class

        Module MyThread
        Public ThatForm As Form1

        Public Sub MyThreadExecute()
            Dim i As Integer = 0
            Do
                i = i + 1
                ThatForm.SetProgress(i)
                Thread.Sleep(100)
            Loop
        End Sub
        

        End Module

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups