473,507 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

call sub from 2 thread at same time?

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
Nov 21 '05 #1
1 2076
On Mon, 13 Sep 2004 09:05:48 -0700, Steve wrote:
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....

--
Tom Shelton [MVP]
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2826
by: Prasad | last post by:
Hi, I am writing a service which takes a long time to stop after the OnStop call is given by the Services Snap-in. The problem is I cannot cut down on the time that it takes to Stop. The Service...
0
1254
by: JDK | last post by:
This may be entirely the wrong forum for this message, but I wanted to give it a try. I am creating an ASPX page, with C# code behind, and am calling on a C# helper class, which in turn is...
20
3942
by: Cybertof | last post by:
Hello, Is there a good way to call a big time-consumming function from an ActiveX DLL (interoped) through a thread without blocking the main UI ? Here are the details : I have a class...
3
1491
by: Dave | last post by:
I have a piece of hardware connected via serial port. I need to send a variety of commands to the box and route the responses back from the receive thread to the correct method call. So e.g. I...
9
1573
by: wdwedw | last post by:
I have included all the source codes in the attached MyTest.zip (http://www.codeguru.com/forum/attachment.php?attachmentid=11218) There are three projects: VBTestCOM project is a apartment...
0
2932
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
5
3238
by: Paul Hasell | last post by:
Hi, I'm trying to invoke a web method asynchronously but just can't seem to get it to tell me when it has finished! Below is the code I am (currently) using: private void...
3
4656
by: =?Utf-8?B?Y2hlbmRyaWNrcw==?= | last post by:
I have a C# winforms application that makes periodic web service calls in background thread to my web service server. These calls work fine almost all the time but on rare occassions the web...
2
5545
by: =?Utf-8?B?SmltIE93ZW4=?= | last post by:
Hi John, Hopefully this post will find its way back to you - or perhaps be answered by someone else. As I mentioned in my last post on the earlier portion of this thread, changing the...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.