VB.Net Create a new thread

  • Thread starter Thread starter Ron Weiner
  • Start date Start date
R

Ron Weiner

I would like to start a print job running on its own thread in order to give
control back to the user as soon as possible. I have created a sub
PrintOneRecord(intRecordID) that does the deed. I thought I could start the
print job running on its own thread by coding something like this:

Dim MyThread As New System.Threading.Thread(AddressOf
PrintOneRecord(intRecordID))
MyThread.Priority = Threading.ThreadPriority.BelowNormal
MyThread.Start()

But this give an error in the editor "AddressOf operator must be the name of
a method; no parentheses are needed"

Changing it to:

Dim MyThread As New System.Threading.Thread(AddressOf PrintOneRecord)
MyThread.Priority = Threading.ThreadPriority.BelowNormal
MyThread.Start()

Gives an even better error message "Method 'Public Sub
PrintOneRecord(intDatID as Integer)' does not have the same signature as
delegate 'Delegate Sub Thread start'."

Can some one help me sort this out. All I want to do is to start a new
thread running the Sub PrintOneRecord and pass it the RecordID that needs to
get printed.
 
A thread proc must be defined as Sub MyProc() so no parameters are allowed,
which is what the compiler is telling you.

-Chris
 
Thanks Chris.
I got around this by pointing the thread to a new Sub that calls the the
PrintOneRecord sub with the appropriate prameter. It all seems to be
working OK.
 
Back
Top