True multithreading

Discussion in 'Programming General' started by TheDarkExistence, Dec 11, 2010.

True multithreading
  1. Unread #1 - Dec 11, 2010 at 12:02 PM
  2. TheDarkExistence
    Joined:
    Jul 4, 2009
    Posts:
    12
    Referrals:
    0
    Sythe Gold:
    0

    TheDarkExistence Newcomer

    True multithreading

    Alright so I've created a Grand Exchange parser and all the info gets pumped into a listview...Now I don't want the app to freeze while the shit is being loaded, so I tried to multithread, but I don't think I'm doing it right. I tried adding a new thread then putting my instructions into that thread, but then I'd get CrossThreadException errors or something like that, because the thread was trying to reference an object outside of itself (the listview). So, I then checked to see if the form required an invoke, and if it did, to do it to try and remove the error:
    Code:
    If Me.InvokeRequired = True Then
    Me.Invoke(New MethodInvoker(AddressOf ParseGE()))
    Else
    ParseGE()
    End If
    
    So now I don't get the error, but it's as though there was no thread added at all in the first place since the application still freezes. I've also tried using the BackgroundProcess object but nothing seems to be working! Please help :(
     
  3. Unread #2 - Dec 11, 2010 at 2:15 PM
  4. Harlem9191
    Joined:
    Mar 10, 2009
    Posts:
    81
    Referrals:
    0
    Sythe Gold:
    0

    Harlem9191 Member

    True multithreading

    Code:
    Private Sub ParseGe()
    If Me.InvokeRequired = True Then
    Me.Invoke(New MethodInvoker(AddressOf ParseGE))
    Else
    
    'CODE YOU WANT TO INVOKE GOES HERE
    
    End If
    End Sub
    
    You only need to invoke when you are accessing a control on your form. Processes do not need to be invoked.

    For example:
    You might want to use a loop to do a process on an array of integers (maybe times each integer by 2) and then display them in a listview. The process can be done on a different thread but as your form is working on a different thread to your process controls cannot be accessed unless you invoke. So when the loop adds the integers to the listview you must invoke so that the control can be accessed from the other thread.
     
< What should I compile this with? | Java could not create the virtual machine >

Users viewing this thread
1 guest


 
 
Adblock breaks this site