• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

VB threads

I have threads running and one of them needs to spawn a standalone process/thread that will do independent processing.  I need this to run in background.  I also need it to be spawned again while the first is still running.  I just barely know about threads.  In an attempt to do this I used the code below.  All of it is in the same class.

It is not reentrant.
Public pro_train As Thread
    Public Processing As New Process_Train
 
   pro_train = New Thread(AddressOf Me.ProcessTheTrain)
   pro_train.Priority = ThreadPriority.Lowest
   pro_train.Start()
 
    Sub ProcessTheTrain()
            Processing.CCLPS_Main(OutputFileName)
 
    End Sub

Open in new window

0
fsoucy
Asked:
fsoucy
  • 2
  • 2
1 Solution
 
obrienslalomCommented:
The code looks like you have the right idea.  What problems are you having?
This link is certainly worth a read:
http://www.albahari.com/threading/
If you plan on writing lots of concurrent programs, you may want to pick up Joe Duffy's "Concurrent programming on Windows" book.
Also, you probably want to add this to the VB zone.
0
 
fsoucyAuthor Commented:
The standalone thread is not relinquishing the CPU enough to allow other threads to operate in near real time.  The real time threads are set to a priority of High.

I tried to remidy this by adding DoEvents in places where there was loops with a large amount of iteration.  All that did was slow the background process.
0
 
obrienslalomCommented:
The 'real time' threads you are referring to are for the GUI?

When you spawn off the new thread, it will not discriminate between the two threads.  If you are seeing the application hang, something else might be going on.  Try not to use DoEvents until you know the messages are stuck in the message queue.
0
 
fsoucyAuthor Commented:
The real time threads are for data capture through high speed serial ports.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now