call sub from 2 thread at same time?

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hello,

Is it possible to call a sub routine from 2 different
threads at the same time? Or should I create a class
containing this sub and instantiate the class for each
thread? The sub pulls data from different data sources
but the same structure. Right now I have 2 separate forms
with the same sub. If I call both forms from the 2
threads I can pull the data faster than calling the sub
for datasource1 and then calling the sub for datasoruce2.

So, right now I call 2 different class modules (2
different forms). Even if I have to go the class route, I
am hoping I could have one class that I could instantiate
with the various parameters. Or, if it is possible to
just invoke the sub without the class, that would be the
simplest. Any suggestions appreciated.

Thanks,
Steve
 
Hello,

Is it possible to call a sub routine from 2 different
threads at the same time? Or should I create a class
containing this sub and instantiate the class for each
thread? The sub pulls data from different data sources
but the same structure. Right now I have 2 separate forms
with the same sub. If I call both forms from the 2
threads I can pull the data faster than calling the sub
for datasource1 and then calling the sub for datasoruce2.

So, right now I call 2 different class modules (2
different forms). Even if I have to go the class route, I
am hoping I could have one class that I could instantiate
with the various parameters. Or, if it is possible to
just invoke the sub without the class, that would be the
simplest. Any suggestions appreciated.

Thanks,
Steve

Sure it's possilbe...

Dim t1 As New Thread (AddressOf threadproc)
Dim t2 as new thread (AddressOf threadproc)

sub threadproc()
end sub

The gotcha is if these subs are using any shared data... If they are
accessing shared resources, then you'll want to look at the SyncLock
statement or one of the syncronization objects found in the
system.threading namespace....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top