473,669 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Start 20 Threads, stop them all after 10 seconds

Hi

I was wondering if someone could help me with the syntax for some VB.Net
ASPX code to:

- Start 20 threads
- End all threads after the sooner of 10 seconds or if all of the threads
themselves have finished.

BTW, each thread checks an email address for validity with www.aspnetmx.com.
If it is taking too long (e.g. > 10 seconds) I just want to look at the
results for the threads that have finished.

TIA
Mark

Nov 19 '05 #1
7 1735
Mark,

The most simple way is to set them first in an array and than to abort them
using a timer in your main program. (I doubt if it really will work.)

As I understand it well, does this mean that if you have 100 sessions
active, that than you have 2000 threads active in your system.

Now I see even less purpose of your threading. (Probably your processor time
is eaten by the processing of those threads)

However just my thought of course.

Cor
Nov 19 '05 #2
well in my opinion a asynchrone started dellegate would be a much cleaner
solution in this situation
just my 2 cents

Michel Posseth [MCP]
"Mark B" <mb*******@Dele te-All-X-XorbisofXXt.com > schreef in bericht
news:er******** ******@TK2MSFTN GP14.phx.gbl...
Hi

I was wondering if someone could help me with the syntax for some VB.Net
ASPX code to:

- Start 20 threads
- End all threads after the sooner of 10 seconds or if all of the threads
themselves have finished.

BTW, each thread checks an email address for validity with
www.aspnetmx.com.
If it is taking too long (e.g. > 10 seconds) I just want to look at the
results for the threads that have finished.

TIA
Mark


Nov 19 '05 #3
Thanks. OK then, here's the code I could use:

'********CODE START********** *****
Dim intResult(20) as Integer = 1
Dim i as Integer
'intResult(i) 1 = Not Finished, 2 = True , 3 =False

For i = 1 To 20

'*******Start thread (i) here
If Mx.Validate(Ses sion("Email"+Fo rmat$(i,"00"))) =True Then
'This tests the particular email address
intResult(i)= 2
Else
intResult(i)= 3
End If
' *********End thread (i)i here

Next i

'********CODE END************ ***
Can someone help me with the threading syntax I should use above where it
says:

'*******Start thread i here
and
' *********End thread i here

and also the main engine code to shut down the threads after 10 seconds.
Then the 20 session variables can be inspected to see which ones passed,
failed and timed-out.
TIA
Mark

P.S. "As I understand it well, does this mean that if you have 100 sessions
active, that than you have 2000 threads active in your system." True, but
the threads are only active for 10 seconds per session. We can see how it
goes.


"Cor Ligthert" <no************ @planet.nl> wrote in message
news:OG******** ******@TK2MSFTN GP09.phx.gbl...
Mark,

The most simple way is to set them first in an array and than to abort them using a timer in your main program. (I doubt if it really will work.)

As I understand it well, does this mean that if you have 100 sessions
active, that than you have 2000 threads active in your system.

Now I see even less purpose of your threading. (Probably your processor time is eaten by the processing of those threads)

However just my thought of course.

Cor

Nov 19 '05 #4
Mark,
In addition to the other comments:

Directly creating threads can be costly, rather then use New Thread, I would
recommend using either the ThreadPool, creating your own thread pool, or
using an async delegate.

The following MSDN Magazine article shows one method of creating a timed
method.

http://msdn.microsoft.com/msdnmag/is...s/default.aspx
Depending on how you call www.aspnetmx.com, for example if its a Web Service
wouldn't it be easier to simply set the WebClientProtoc ol.Timeout property
to your timeout amount (10 seconds)?

http://msdn.microsoft.com/library/de...meouttopic.asp

Something like:

'********CODE START********** *****

' set the method timeout on the proxy to 10 seconds
Mx.Timeout = CInt(TimeSpan.F romSeconds(10). TotalMillisecon ds)
Dim intResult(20) as Integer = 1
Dim i as Integer
'intResult(i) 1 = Not Finished, 2 = True , 3 =False

For i = 1 To 20

'*******Start thread (i) here
If Mx.Validate(Ses sion("Email"+Fo rmat$(i,"00"))) =True Then
'This tests the particular email address
intResult(i)= 2
Else
intResult(i)= 3
End If
' *********End thread (i)i here

Next i

'********CODE END************ ***

Also, depending on how may total requests I had coming in, I would consider
doing these 20 outgoing requests asynchronously.

Something like (syntax checked only):

Mx.Timeout = CInt(TimeSpan.F romSeconds(10). TotalMillisecon ds)

Dim intResults(20 - 1) As Integer

Dim results(20 - 1) As IAsyncResult

' Queue up all the requests
For index As Integer = 0 To 20 - 1

intResults(inde x) = 1
results(index) =
Mx.BeginValidat e(Session("Emai l"+Format$(i,"0 0)), nothing, nothing)

Next index

' wait for each request to finish
For index As Integer = 0 To 20 - 1
If Mx.EndValidate( results(index)) Then
'This tests the particular email address
intResults(inde x)= 2
Else
intResults(inde x)= 3
End If
Next

NOTE: You may need the Mx.EndValidate in a Try/Catch as the Timeout will
cause an exception to be raised...

The advantage of using BeginValidate is that all 20 validates are executing
concurrently...

Hope this helps
Jay

"Mark B" <mb*******@Dele te-All-X-XorbisofXXt.com > wrote in message
news:er******** ******@TK2MSFTN GP14.phx.gbl...
| Hi
|
| I was wondering if someone could help me with the syntax for some VB.Net
| ASPX code to:
|
| - Start 20 threads
| - End all threads after the sooner of 10 seconds or if all of the threads
| themselves have finished.
|
| BTW, each thread checks an email address for validity with
www.aspnetmx.com.
| If it is taking too long (e.g. > 10 seconds) I just want to look at the
| results for the threads that have finished.
|
| TIA
| Mark
|
|
|
|
|

Nov 19 '05 #5
Thanks very much.

I haven't really programmed much in VB.Net before just VBA.

I couldn't find the method "BeginValid ate" or "EndValidat e" in the ASPNetMX
documentation at http://www.aspnetmx.com/help/default.htm. Where does it
come from?

Also, excuse my .Net ignorance but does "asynchronously " mean at the same
time?

And, is "For index As Integer = 0 To 20 - 1" the same as:

Dim index as Integer
For index = 0 To 19

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:uS******** ******@TK2MSFTN GP09.phx.gbl...
Mark,
In addition to the other comments:

Directly creating threads can be costly, rather then use New Thread, I would recommend using either the ThreadPool, creating your own thread pool, or
using an async delegate.

The following MSDN Magazine article shows one method of creating a timed
method.

http://msdn.microsoft.com/msdnmag/is...s/default.aspx
Depending on how you call www.aspnetmx.com, for example if its a Web Service wouldn't it be easier to simply set the WebClientProtoc ol.Timeout property
to your timeout amount (10 seconds)?

http://msdn.microsoft.com/library/de...meouttopic.asp
Something like:

'********CODE START********** *****

' set the method timeout on the proxy to 10 seconds
Mx.Timeout = CInt(TimeSpan.F romSeconds(10). TotalMillisecon ds)
Dim intResult(20) as Integer = 1
Dim i as Integer
'intResult(i) 1 = Not Finished, 2 = True , 3 =False

For i = 1 To 20

'*******Start thread (i) here
If Mx.Validate(Ses sion("Email"+Fo rmat$(i,"00"))) =True Then
'This tests the particular email address
intResult(i)= 2
Else
intResult(i)= 3
End If
' *********End thread (i)i here

Next i

'********CODE END************ ***

Also, depending on how may total requests I had coming in, I would consider doing these 20 outgoing requests asynchronously.

Something like (syntax checked only):

Mx.Timeout = CInt(TimeSpan.F romSeconds(10). TotalMillisecon ds)

Dim intResults(20 - 1) As Integer

Dim results(20 - 1) As IAsyncResult

' Queue up all the requests
For index As Integer = 0 To 20 - 1

intResults(inde x) = 1
results(index) =
Mx.BeginValidat e(Session("Emai l"+Format$(i,"0 0)), nothing, nothing)

Next index

' wait for each request to finish
For index As Integer = 0 To 20 - 1
If Mx.EndValidate( results(index)) Then
'This tests the particular email address
intResults(inde x)= 2
Else
intResults(inde x)= 3
End If
Next

NOTE: You may need the Mx.EndValidate in a Try/Catch as the Timeout will
cause an exception to be raised...

The advantage of using BeginValidate is that all 20 validates are executing concurrently...

Hope this helps
Jay

"Mark B" <mb*******@Dele te-All-X-XorbisofXXt.com > wrote in message
news:er******** ******@TK2MSFTN GP14.phx.gbl...
| Hi
|
| I was wondering if someone could help me with the syntax for some VB.Net
| ASPX code to:
|
| - Start 20 threads
| - End all threads after the sooner of 10 seconds or if all of the threads | themselves have finished.
|
| BTW, each thread checks an email address for validity with
www.aspnetmx.com.
| If it is taking too long (e.g. > 10 seconds) I just want to look at the
| results for the threads that have finished.
|
| TIA
| Mark
|
|
|
|
|

Nov 19 '05 #6
Did you read my reply from last week? I spent a long time covering this. I
recommended that you do not use multiple threads. Perhaps that isn't what
you wanted to hear, but I gave you quite a few good reasons not to.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Mark B" <mb*******@Dele te-All-X-XorbisofXXt.com > wrote in message
news:uu******** ******@TK2MSFTN GP09.phx.gbl...
Thanks very much.

I haven't really programmed much in VB.Net before just VBA.

I couldn't find the method "BeginValid ate" or "EndValidat e" in the
ASPNetMX
documentation at http://www.aspnetmx.com/help/default.htm. Where does it
come from?

Also, excuse my .Net ignorance but does "asynchronously " mean at the same
time?

And, is "For index As Integer = 0 To 20 - 1" the same as:

Dim index as Integer
For index = 0 To 19

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:uS******** ******@TK2MSFTN GP09.phx.gbl...
Mark,
In addition to the other comments:

Directly creating threads can be costly, rather then use New Thread, I

would
recommend using either the ThreadPool, creating your own thread pool, or
using an async delegate.

The following MSDN Magazine article shows one method of creating a timed
method.

http://msdn.microsoft.com/msdnmag/is...s/default.aspx
Depending on how you call www.aspnetmx.com, for example if its a Web

Service
wouldn't it be easier to simply set the WebClientProtoc ol.Timeout
property
to your timeout amount (10 seconds)?

http://msdn.microsoft.com/library/de...meouttopic.asp

Something like:

'********CODE START********** *****

' set the method timeout on the proxy to 10 seconds
Mx.Timeout = CInt(TimeSpan.F romSeconds(10). TotalMillisecon ds)
Dim intResult(20) as Integer = 1
Dim i as Integer
'intResult(i) 1 = Not Finished, 2 = True , 3 =False

For i = 1 To 20

'*******Start thread (i) here
If Mx.Validate(Ses sion("Email"+Fo rmat$(i,"00"))) =True Then
'This tests the particular email address
intResult(i)= 2
Else
intResult(i)= 3
End If
' *********End thread (i)i here

Next i

'********CODE END************ ***

Also, depending on how may total requests I had coming in, I would

consider
doing these 20 outgoing requests asynchronously.

Something like (syntax checked only):

Mx.Timeout = CInt(TimeSpan.F romSeconds(10). TotalMillisecon ds)

Dim intResults(20 - 1) As Integer

Dim results(20 - 1) As IAsyncResult

' Queue up all the requests
For index As Integer = 0 To 20 - 1

intResults(inde x) = 1
results(index) =
Mx.BeginValidat e(Session("Emai l"+Format$(i,"0 0)), nothing, nothing)

Next index

' wait for each request to finish
For index As Integer = 0 To 20 - 1
If Mx.EndValidate( results(index)) Then
'This tests the particular email address
intResults(inde x)= 2
Else
intResults(inde x)= 3
End If
Next

NOTE: You may need the Mx.EndValidate in a Try/Catch as the Timeout will
cause an exception to be raised...

The advantage of using BeginValidate is that all 20 validates are

executing
concurrently...

Hope this helps
Jay

"Mark B" <mb*******@Dele te-All-X-XorbisofXXt.com > wrote in message
news:er******** ******@TK2MSFTN GP14.phx.gbl...
| Hi
|
| I was wondering if someone could help me with the syntax for some
VB.Net
| ASPX code to:
|
| - Start 20 threads
| - End all threads after the sooner of 10 seconds or if all of the

threads
| themselves have finished.
|
| BTW, each thread checks an email address for validity with
www.aspnetmx.com.
| If it is taking too long (e.g. > 10 seconds) I just want to look at the
| results for the threads that have finished.
|
| TIA
| Mark
|
|
|
|
|


Nov 19 '05 #7
Mark,
| I couldn't find the method "BeginValid ate" or "EndValidat e" in the
ASPNetMX
| documentation at http://www.aspnetmx.com/help/default.htm. Where does it
| come from?
"BeginValid ate" or "EndValidat e" are based on ASPNetMX being a Web Service,
ASPNetMX is not a web service, ergo they don't exist per se. You should be
able to use an asynchronous delegate with ASPNetMX.

http://msdn.microsoft.com/library/de...sdelegates.asp

| Also, excuse my .Net ignorance but does "asynchronously " mean at the same
| time?
Yes. For details on asynchronous programming see:

http://msdn.microsoft.com/library/de...rogramming.asp
| And, is "For index As Integer = 0 To 20 - 1" the same as:
|
| Dim index as Integer
| For index = 0 To 19
Yes

| I haven't really programmed much in VB.Net before just VBA.

Looking at http://www.aspnetmx.com/help/default.htm, I would consider using
ValidateQty instead of Validate, as ValidateQty does a list of addresses.
Then I would not worry about getting multi-threading & asynchronous
programming to work. As Kevin suggests multi-threading is something to
consider not using, as it is a very advanced topic that is easy to make
things worse then better, although I have not specifically read Kevin's
response... Asynchronous programming ("BeginValidate " or "EndValidat e") are
generally easier, however even then you need to be very careful as its still
multi-threaded programming.

Hope this helps
Jay

"Mark B" <mb*******@Dele te-All-X-XorbisofXXt.com > wrote in message
news:uu******** ******@TK2MSFTN GP09.phx.gbl...
| Thanks very much.
|
| I haven't really programmed much in VB.Net before just VBA.
|
| I couldn't find the method "BeginValid ate" or "EndValidat e" in the
ASPNetMX
| documentation at http://www.aspnetmx.com/help/default.htm. Where does it
| come from?
|
| Also, excuse my .Net ignorance but does "asynchronously " mean at the same
| time?
|
| And, is "For index As Integer = 0 To 20 - 1" the same as:
|
| Dim index as Integer
| For index = 0 To 19
|
|
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
| news:uS******** ******@TK2MSFTN GP09.phx.gbl...
| > Mark,
| > In addition to the other comments:
| >
| > Directly creating threads can be costly, rather then use New Thread, I
| would
| > recommend using either the ThreadPool, creating your own thread pool, or
| > using an async delegate.
| >
| > The following MSDN Magazine article shows one method of creating a timed
| > method.
| >
| > http://msdn.microsoft.com/msdnmag/is...s/default.aspx
| >
| >
| > Depending on how you call www.aspnetmx.com, for example if its a Web
| Service
| > wouldn't it be easier to simply set the WebClientProtoc ol.Timeout
property
| > to your timeout amount (10 seconds)?
| >
| >
|
http://msdn.microsoft.com/library/de...meouttopic.asp
| >
| > Something like:
| >
| > '********CODE START********** *****
| >
| > ' set the method timeout on the proxy to 10 seconds
| > Mx.Timeout = CInt(TimeSpan.F romSeconds(10). TotalMillisecon ds)
| >
| >
| > Dim intResult(20) as Integer = 1
| > Dim i as Integer
| > 'intResult(i) 1 = Not Finished, 2 = True , 3 =False
| >
| > For i = 1 To 20
| >
| > '*******Start thread (i) here
| > If Mx.Validate(Ses sion("Email"+Fo rmat$(i,"00"))) =True Then
| > 'This tests the particular email address
| > intResult(i)= 2
| > Else
| > intResult(i)= 3
| > End If
| > ' *********End thread (i)i here
| >
| > Next i
| >
| > '********CODE END************ ***
| >
| > Also, depending on how may total requests I had coming in, I would
| consider
| > doing these 20 outgoing requests asynchronously.
| >
| > Something like (syntax checked only):
| >
| > Mx.Timeout = CInt(TimeSpan.F romSeconds(10). TotalMillisecon ds)
| >
| > Dim intResults(20 - 1) As Integer
| >
| > Dim results(20 - 1) As IAsyncResult
| >
| > ' Queue up all the requests
| > For index As Integer = 0 To 20 - 1
| >
| > intResults(inde x) = 1
| > results(index) =
| > Mx.BeginValidat e(Session("Emai l"+Format$(i,"0 0)), nothing, nothing)
| >
| > Next index
| >
| > ' wait for each request to finish
| > For index As Integer = 0 To 20 - 1
| > If Mx.EndValidate( results(index)) Then
| > 'This tests the particular email address
| > intResults(inde x)= 2
| > Else
| > intResults(inde x)= 3
| > End If
| > Next
| >
| > NOTE: You may need the Mx.EndValidate in a Try/Catch as the Timeout will
| > cause an exception to be raised...
| >
| > The advantage of using BeginValidate is that all 20 validates are
| executing
| > concurrently...
| >
| > Hope this helps
| > Jay
| >
| > "Mark B" <mb*******@Dele te-All-X-XorbisofXXt.com > wrote in message
| > news:er******** ******@TK2MSFTN GP14.phx.gbl...
| > | Hi
| > |
| > | I was wondering if someone could help me with the syntax for some
VB.Net
| > | ASPX code to:
| > |
| > | - Start 20 threads
| > | - End all threads after the sooner of 10 seconds or if all of the
| threads
| > | themselves have finished.
| > |
| > | BTW, each thread checks an email address for validity with
| > www.aspnetmx.com.
| > | If it is taking too long (e.g. > 10 seconds) I just want to look at
the
| > | results for the threads that have finished.
| > |
| > | TIA
| > | Mark
| > |
| > |
| > |
| > |
| > |
| >
| >
| >
|
|
Nov 19 '05 #8

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

Similar topics

2
5283
by: 0to60 | last post by:
I have a windows service that when started creates two threads: one thread that runs a TcpListener waiting for TcpClients to connect, and another thread that reads from the resulting sockets. My stop code .Abort()s the threads and .Stop()s the listener. One one of my computers, the service runs like, well...a service. It starts and stops nicely. On a different computer (eventually this service will be running on 50+ machines) the...
21
1625
by: Doug Thews | last post by:
I was noticing that when I run a multi-threaded app from within the IDE and then I close the main form (which spun off all of the threads), that the Stop/Pause VCR buttons in the debugger are still available & working. It's like closing the form did not actually cancel the threads. From my earlier discussions on the newsgroup, I know how people already feel about Thread.Abort(), so I was wondering what I need to do to "clean up" when...
9
1871
by: Eric Sabine | last post by:
Can someone give me a practical example of why I would join threads? I am assuming that you would typically join a background thread with the UI thread and not a background to a background, but since I'm asking in the first place, assume that assumption to be very assuming. thanks, Eric
8
2368
by: Mark B | last post by:
Hi I was wondering if someone could help me with the syntax for some VB.Net ASPX code to: - Start 20 threads - End all threads after the sooner of 10 seconds or if all of the threads themselves have finished. BTW, each thread checks an email address for validity with www.aspnetmx.com.
37
8878
by: ales | last post by:
Hello, I have a problem with creation of new thread. The method .Start() of newly created thread delays current thread for 0 - 1 second. Cpu while delay occurs is about 5%. Any idea? Here is code used for measuring:
6
5394
by: Alexander Walker | last post by:
Hello Is it inefficient to create an application that has many threads that individually may do a small amount of work over a given period of time as opposed to an application that has a smaller number of threads that do a larger amount of work over a given time period here is an oversimplified example application 1 has 4 threads
17
6409
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this problem. The operating system is MS Windows XP Professional.
5
4762
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a set of sensor data per second to a socket server. The socket server will do two things: 1. write data into a file via bsddb; 2. forward the data to a GUI written in wxpython. I am thinking the code should work as follow (not sure it is feasible)...
0
971
by: bennett | last post by:
Hi All, I am making a web service that needs make several calls to different websites and format the website responses into the same format using XSLT. Currently I am just using an array of threads that starts a class with a complete/done event handler. When each feed has finished it increments a counter so I can see how many thread were fired off and how many completed. The problem is i don't want any of the threads to take longer...
0
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
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 we have to send another system

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.