473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2471
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*****@comcast.net> wrote in message
news:%2****************@TK2MSFTNGP10.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**************@TK2MSFTNGP09.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*****@comcast.net> wrote in message
news:%2****************@TK2MSFTNGP10.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.Threading.ThreadPool.QueueUserWorkItem 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 MyMainThreadProcessingLoop()
...
'This is where you fire off your threads
Dim state as new StateHolder
state.id = someIDValueFromTheLoop
System.Threading.ThreadPool.QueueUserWorkItem(Addr essOf(DoSomething),
state)
...
End Sub

Public Sub DoSomething(State 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*****@comcast.net> wrote in message
news:ei**************@TK2MSFTNGP10.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**************@TK2MSFTNGP09.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*****@comcast.net> wrote in message
news:%2****************@TK2MSFTNGP10.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****************@tk2msftngp13.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.Threading.ThreadPool.QueueUserWorkItem 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 MyMainThreadProcessingLoop()
...
'This is where you fire off your threads
Dim state as new StateHolder
state.id = someIDValueFromTheLoop
System.Threading.ThreadPool.QueueUserWorkItem(Addr essOf(DoSomething),
state)
...
End Sub

Public Sub DoSomething(State 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*****@comcast.net> wrote in message
news:ei**************@TK2MSFTNGP10.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**************@TK2MSFTNGP09.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*****@comcast.net> wrote in message
news:%2****************@TK2MSFTNGP10.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 QueueUserWorkItem, although you may need to wait a bit for
that.)


"Jeremy" <ww*****@comcast.net> wrote in message
news:%2****************@TK2MSFTNGP09.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****************@tk2msftngp13.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.Threading.ThreadPool.QueueUserWorkItem 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 MyMainThreadProcessingLoop()
...
'This is where you fire off your threads
Dim state as new StateHolder
state.id = someIDValueFromTheLoop
System.Threading.ThreadPool.QueueUserWorkItem(Addr essOf(DoSomething), state)
...
End Sub

Public Sub DoSomething(State 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*****@comcast.net> wrote in message
news:ei**************@TK2MSFTNGP10.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**************@TK2MSFTNGP09.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*****@comcast.net> wrote in message
> news:%2****************@TK2MSFTNGP10.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
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...
2
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...
11
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...
2
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...
1
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...
2
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...
9
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.