473,756 Members | 5,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Spawning multiple processes at same time

I have a core VB service that monitors a database, and based on data in the
records will execute code to send email notifications.

Problem:
I don't want my main program code to halt and wait for this execution... we
need immediate execution of all notification processes and would prefer to
spawn multiple instances generating emails at one time.

Solution ?
I took a look at threading, and at first it looked to be the answer.
Unfortunately, I need to spawn an unlimited amount of processes (maybe
manage the number based on resources) and threads have to be Dim'd and
executed one at a time. Not what I am looking for.

So, any ideas?

Jeremy
Nov 20 '05 #1
5 2490
I think a bit more information on the problem you're trying to solve may
help you get solution sugesstions.

Your "problem" with threads sounds a bit like you may not have a handle on
them: They can execute "at the same time", not one at a time. Yes, they
have to be created and started at some point, but they will be lighter
weight than the same number of processes.
"Jeremy" <ww*****@comcas t.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a core VB service that monitors a database, and based on data in the records will execute code to send email notifications.

Problem:
I don't want my main program code to halt and wait for this execution... we need immediate execution of all notification processes and would prefer to
spawn multiple instances generating emails at one time.

Solution ?
I took a look at threading, and at first it looked to be the answer.
Unfortunately, I need to spawn an unlimited amount of processes (maybe
manage the number based on resources) and threads have to be Dim'd and
executed one at a time. Not what I am looking for.

So, any ideas?

Jeremy

Nov 20 '05 #2
That is true. I have used them in the past to complete concurrent processes
and then return with the results to the controlling UI. In this case, I
need to create an unknown number of concurrent processes to create email
notifications.

More information:
I am basically writing my own scheduler program. It queries our database to
pull down the execution pattern for all applications that use its email
notification process. I allow the application developers to set the
interval or schedule via database entries. In some cases it would be an
interval, such as every 10 minutes, while others are more of a set schedule,
like every Tuesday at 11pm.

I pull down a complete list of the applications, there schedule and the last
time they ran. I then calculate if they need to run. This is where I would
like to just spawn a process to handle the email text generation, which
would be based on the specific application, and then continue working
through the application list to find any others that need to be run.

I plan to insert a database flag so I know I ran a given application
already, but the core process doesn't care how the spawned process ends. If
errors occur, I will handle logging them in the spawned process. The core
process is to just keep on moving.

It comes down to the potential of the spawning process... I don't have a set
number that could be executed, therefore I don't believe I can use threads
since I can't dynamically name a variable and create it as a thread for
execution.

Comments? Solution?

"Philip Rieck" <st***@mckraken .com> wrote in message
news:eA******** ******@TK2MSFTN GP09.phx.gbl...
I think a bit more information on the problem you're trying to solve may
help you get solution sugesstions.

Your "problem" with threads sounds a bit like you may not have a handle on
them: They can execute "at the same time", not one at a time. Yes, they
have to be created and started at some point, but they will be lighter
weight than the same number of processes.
"Jeremy" <ww*****@comcas t.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a core VB service that monitors a database, and based on data in

the
records will execute code to send email notifications.

Problem:
I don't want my main program code to halt and wait for this execution...

we
need immediate execution of all notification processes and would prefer to spawn multiple instances generating emails at one time.

Solution ?
I took a look at threading, and at first it looked to be the answer.
Unfortunately, I need to spawn an unlimited amount of processes (maybe
manage the number based on resources) and threads have to be Dim'd and
executed one at a time. Not what I am looking for.

So, any ideas?

Jeremy


Nov 20 '05 #3
I can give you just a few observations. Sounds like a fun little project,
though!

1) You probably don't want to fire off a thread for each email to be sent -
if there are lots of threads / processes running a computer will spend all
its time switching contexts and not enough time running your code. (besides
the whole resource starvation issue)

2) You can use System.Threadin g.ThreadPool.Qu eueUserWorkItem to have a
delegate called on a separate thread. All the plumbing of making sure the
threads are scheduled correctly is already done for you. Kind of a "Here do
this when you can" facility. Note that this has some issues with possible
thread starvation, and ASP.NET uses these internally as well, so go into it
with eyes open. However, this does seem like a good possibility for your
problem.

3) Async delegates may be a possibility for you.

4) You could use an ArrayList of Thread objects to start and control them.

Concept example for #2

Public Class StateHolder
'This class holds state information to be passed from thread to thread
Public id as Integer
End Class
....

Public Sub MyMainThreadPro cessingLoop()
...
'This is where you fire off your threads
Dim state as new StateHolder
state.id = someIDValueFrom TheLoop
System.Threadin g.ThreadPool.Qu eueUserWorkItem (AddressOf(DoSo mething),
state)
...
End Sub

Public Sub DoSomething(Sta te as Object)
Dim s as StateHolder = CType(State, StateHolder)
'Now I have my information, do something. This Sub will be called
on a separate thread!
...
End Sub

"Jeremy" <ww*****@comcas t.net> wrote in message
news:ei******** ******@TK2MSFTN GP10.phx.gbl...
That is true. I have used them in the past to complete concurrent processes and then return with the results to the controlling UI. In this case, I
need to create an unknown number of concurrent processes to create email
notifications.

More information:
I am basically writing my own scheduler program. It queries our database to pull down the execution pattern for all applications that use its email
notification process. I allow the application developers to set the
interval or schedule via database entries. In some cases it would be an
interval, such as every 10 minutes, while others are more of a set schedule, like every Tuesday at 11pm.

I pull down a complete list of the applications, there schedule and the last time they ran. I then calculate if they need to run. This is where I would like to just spawn a process to handle the email text generation, which
would be based on the specific application, and then continue working
through the application list to find any others that need to be run.

I plan to insert a database flag so I know I ran a given application
already, but the core process doesn't care how the spawned process ends. If errors occur, I will handle logging them in the spawned process. The core
process is to just keep on moving.

It comes down to the potential of the spawning process... I don't have a set number that could be executed, therefore I don't believe I can use threads
since I can't dynamically name a variable and create it as a thread for
execution.

Comments? Solution?

"Philip Rieck" <st***@mckraken .com> wrote in message
news:eA******** ******@TK2MSFTN GP09.phx.gbl...
I think a bit more information on the problem you're trying to solve may
help you get solution sugesstions.

Your "problem" with threads sounds a bit like you may not have a handle on
them: They can execute "at the same time", not one at a time. Yes, they
have to be created and started at some point, but they will be lighter
weight than the same number of processes.
"Jeremy" <ww*****@comcas t.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a core VB service that monitors a database, and based on data
in the
records will execute code to send email notifications.

Problem:
I don't want my main program code to halt and wait for this
execution... we
need immediate execution of all notification processes and would
prefer to spawn multiple instances generating emails at one time.

Solution ?
I took a look at threading, and at first it looked to be the answer.
Unfortunately, I need to spawn an unlimited amount of processes (maybe
manage the number based on resources) and threads have to be Dim'd and
executed one at a time. Not what I am looking for.

So, any ideas?

Jeremy



Nov 20 '05 #4
Is it possible to execute the same code block (sub) as the process for more
than one thread? I have attempted this with no success.

Jeremy Wood

"Philip Rieck" <st***@mckraken .com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I can give you just a few observations. Sounds like a fun little project,
though!

1) You probably don't want to fire off a thread for each email to be sent - if there are lots of threads / processes running a computer will spend all
its time switching contexts and not enough time running your code. (besides the whole resource starvation issue)

2) You can use System.Threadin g.ThreadPool.Qu eueUserWorkItem to have a
delegate called on a separate thread. All the plumbing of making sure the
threads are scheduled correctly is already done for you. Kind of a "Here do this when you can" facility. Note that this has some issues with possible thread starvation, and ASP.NET uses these internally as well, so go into it with eyes open. However, this does seem like a good possibility for your
problem.

3) Async delegates may be a possibility for you.

4) You could use an ArrayList of Thread objects to start and control them.

Concept example for #2

Public Class StateHolder
'This class holds state information to be passed from thread to thread Public id as Integer
End Class
...

Public Sub MyMainThreadPro cessingLoop()
...
'This is where you fire off your threads
Dim state as new StateHolder
state.id = someIDValueFrom TheLoop
System.Threadin g.ThreadPool.Qu eueUserWorkItem (AddressOf(DoSo mething),
state)
...
End Sub

Public Sub DoSomething(Sta te as Object)
Dim s as StateHolder = CType(State, StateHolder)
'Now I have my information, do something. This Sub will be called
on a separate thread!
...
End Sub

"Jeremy" <ww*****@comcas t.net> wrote in message
news:ei******** ******@TK2MSFTN GP10.phx.gbl...
That is true. I have used them in the past to complete concurrent processes
and then return with the results to the controlling UI. In this case, I
need to create an unknown number of concurrent processes to create email
notifications.

More information:
I am basically writing my own scheduler program. It queries our database to
pull down the execution pattern for all applications that use its email
notification process. I allow the application developers to set the
interval or schedule via database entries. In some cases it would be an
interval, such as every 10 minutes, while others are more of a set schedule,
like every Tuesday at 11pm.

I pull down a complete list of the applications, there schedule and the

last
time they ran. I then calculate if they need to run. This is where I

would
like to just spawn a process to handle the email text generation, which
would be based on the specific application, and then continue working
through the application list to find any others that need to be run.

I plan to insert a database flag so I know I ran a given application
already, but the core process doesn't care how the spawned process ends.

If
errors occur, I will handle logging them in the spawned process. The core process is to just keep on moving.

It comes down to the potential of the spawning process... I don't have a

set
number that could be executed, therefore I don't believe I can use threads since I can't dynamically name a variable and create it as a thread for
execution.

Comments? Solution?

"Philip Rieck" <st***@mckraken .com> wrote in message
news:eA******** ******@TK2MSFTN GP09.phx.gbl...
I think a bit more information on the problem you're trying to solve may help you get solution sugesstions.

Your "problem" with threads sounds a bit like you may not have a handle on them: They can execute "at the same time", not one at a time. Yes,
they have to be created and started at some point, but they will be lighter
weight than the same number of processes.
"Jeremy" <ww*****@comcas t.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> I have a core VB service that monitors a database, and based on data

in the
> records will execute code to send email notifications.
>
> Problem:
> I don't want my main program code to halt and wait for this execution... we
> need immediate execution of all notification processes and would

prefer
to
> spawn multiple instances generating emails at one time.
>
> Solution ?
> I took a look at threading, and at first it looked to be the answer.
> Unfortunately, I need to spawn an unlimited amount of processes (maybe > manage the number based on resources) and threads have to be Dim'd and > executed one at a time. Not what I am looking for.
>
> So, any ideas?
>
> Jeremy
>
>



Nov 20 '05 #5
I've done this many times with no problems.. What kind of issues are you
having?

(there's a quick example of threading with waithandles up on my blog at
http://philiprieck.com/blog/archive/...dleSample.aspx
-- while it's not exactly what we're talking about it does use multiple
threads using the same worker class to provide functionality. let me know
if it helps / doesn't help. Worst case, I can try to find some time to put
up a sample on QueueUserWorkIt em, although you may need to wait a bit for
that.)


"Jeremy" <ww*****@comcas t.net> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Is it possible to execute the same code block (sub) as the process for more than one thread? I have attempted this with no success.

Jeremy Wood

"Philip Rieck" <st***@mckraken .com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I can give you just a few observations. Sounds like a fun little project,
though!

1) You probably don't want to fire off a thread for each email to be sent -
if there are lots of threads / processes running a computer will spend all its time switching contexts and not enough time running your code.

(besides
the whole resource starvation issue)

2) You can use System.Threadin g.ThreadPool.Qu eueUserWorkItem to have a
delegate called on a separate thread. All the plumbing of making sure the threads are scheduled correctly is already done for you. Kind of a "Here do
this when you can" facility. Note that this has some issues with

possible
thread starvation, and ASP.NET uses these internally as well, so go into

it
with eyes open. However, this does seem like a good possibility for your
problem.

3) Async delegates may be a possibility for you.

4) You could use an ArrayList of Thread objects to start and control

them.
Concept example for #2

Public Class StateHolder
'This class holds state information to be passed from thread to

thread
Public id as Integer
End Class
...

Public Sub MyMainThreadPro cessingLoop()
...
'This is where you fire off your threads
Dim state as new StateHolder
state.id = someIDValueFrom TheLoop
System.Threadin g.ThreadPool.Qu eueUserWorkItem (AddressOf(DoSo mething), state)
...
End Sub

Public Sub DoSomething(Sta te as Object)
Dim s as StateHolder = CType(State, StateHolder)
'Now I have my information, do something. This Sub will be called on a separate thread!
...
End Sub

"Jeremy" <ww*****@comcas t.net> wrote in message
news:ei******** ******@TK2MSFTN GP10.phx.gbl...
That is true. I have used them in the past to complete concurrent

processes
and then return with the results to the controlling UI. In this case, I need to create an unknown number of concurrent processes to create email notifications.

More information:
I am basically writing my own scheduler program. It queries our database
to
pull down the execution pattern for all applications that use its email notification process. I allow the application developers to set the
interval or schedule via database entries. In some cases it would be an interval, such as every 10 minutes, while others are more of a set

schedule,
like every Tuesday at 11pm.

I pull down a complete list of the applications, there schedule and the last
time they ran. I then calculate if they need to run. This is where I

would
like to just spawn a process to handle the email text generation,
which would be based on the specific application, and then continue working
through the application list to find any others that need to be run.

I plan to insert a database flag so I know I ran a given application
already, but the core process doesn't care how the spawned process ends. If
errors occur, I will handle logging them in the spawned process. The core process is to just keep on moving.

It comes down to the potential of the spawning process... I don't have
a set
number that could be executed, therefore I don't believe I can use threads since I can't dynamically name a variable and create it as a thread
for execution.

Comments? Solution?

"Philip Rieck" <st***@mckraken .com> wrote in message
news:eA******** ******@TK2MSFTN GP09.phx.gbl...
> I think a bit more information on the problem you're trying to solve

may > help you get solution sugesstions.
>
> Your "problem" with threads sounds a bit like you may not have a handle
on
> them: They can execute "at the same time", not one at a time. Yes,

they > have to be created and started at some point, but they will be lighter > weight than the same number of processes.
>
>
> "Jeremy" <ww*****@comcas t.net> wrote in message
> news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> > I have a core VB service that monitors a database, and based on data in
> the
> > records will execute code to send email notifications.
> >
> > Problem:
> > I don't want my main program code to halt and wait for this

execution...
> we
> > need immediate execution of all notification processes and would

prefer
to
> > spawn multiple instances generating emails at one time.
> >
> > Solution ?
> > I took a look at threading, and at first it looked to be the
answer. > > Unfortunately, I need to spawn an unlimited amount of processes

(maybe > > manage the number based on resources) and threads have to be Dim'd and > > executed one at a time. Not what I am looking for.
> >
> > So, any ideas?
> >
> > Jeremy
> >
> >
>
>



Nov 20 '05 #6

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

Similar topics

7
3310
by: rdh | last post by:
Hi all, I am in process of developing a Server in C++ supporting multiple protocols. The server will be exposing various functionalities, and the clients can communicate over any of the protocols may be TCP, IPX, SAP, NETBEUI to access the server to access the functionalities exposed. The server doesnot know in advance which client is using what protocol. ALSO, ALL THE INTERACTION WILL BE MADE OVER XML. example my server has...
2
2641
by: Dave Kirby | last post by:
I am working on a network management program written in python that has multiple threads (typically 20+) spawning subprocesses which are used to communicate with other systems on the network. This runs fine for a while, but eventually slows down to a crawl. Running sar shows that when it is running slowly there is an exceptionally large number of minor page faults - there are continuously 14000 faults/sec, with a variation of about...
11
5318
by: Mike | last post by:
Looking to find any information on how to properly configure multiple instances of DB2. This is on Win2k db2 ver 7.2. I am basically looking for information on how the multiple instance settings should configured to work, how memory is shared or not, etc. I can not seem to find any good links to this information. Thanks, Mike
2
3234
by: Chris | last post by:
I have a stand-alone program that I want to convert into a client-server type approach so that instead of running several instances of the same program I just spawn new child processes. In theory this should reduce the load on our server :-) As I've never done any of this before could anyone please suggest web-sites or other sources for useful info. I've done a google search, but comes up mainly with distance learning courses for C :-( ...
1
1797
by: Smegly | last post by:
Hi, I currently trying to implement a simulation banking system as part of an assigment. I must stress i do not want line by line code to complete this, what i'm really after is a guide to how i would go about doing this. I need to read a customer from the file customer_list, into a fifo queue, every Ts time. (where Ts is expressed in seconds). Whilst this is happening i also need to have 3 tellers, who when a customer
2
2619
by: Chad McCune | last post by:
I'm developing a portal for our intranet where multiple pages are being shown inside several iframes on a single page. The problem i've ran into, is that it seems as if IIS6/ASP.Net serializes the requests by the user and only processes one *nugget* (iframe) at a time. It handles multiple requests by different users at the same time just fine, just for any one user it only processes 1 request at a time.
9
23083
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated to a pool. If I assign only one application to a applicaton pool and have multiple worker processes assigned to that pool. Will my application be processed by many worker processes?
1
1865
by: mjf | last post by:
Hello, We have seen up to 11 db2fm processes running at the same time, which was consuming 100% of CPU. We could not run anything else on the machine because of this. We have only one DB2 instance, so there should be only one db2fm process. What could be causing so many db2fm processes? Could this be because the fast growing of a table that has a BLOB field? The field holds images, and each image is more than 1MB. Now the table has...
0
9454
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
9271
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
10028
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
9707
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...
1
7242
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6533
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
5139
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
5301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3352
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.