473,748 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Launching Thread w/in a timer service


From a Windows service (NET 2.0) I want to launch serveral threads in
a for loop that invokes a method using:

new Thread(delegate ()
{ myMethod(248);} ).Start();
Will those threads stay active even when the service reaches it Service
Timer Stop?

Do I have to create a thread monitor to test when those threads are
finished before allowing the service to go to the next Timer_Tick?

Jun 7 '07 #1
5 2126
John A. Bailo wrote:
>
From a Windows service (NET 2.0) I want to launch serveral threads in
a for loop that invokes a method using:

new Thread(delegate ()
{ myMethod(248);} ).Start();
Will those threads stay active even when the service reaches it Service
Timer Stop?
Specifically, when it reaches:

private void ServiceTimer_Ti ck(
object sender,
System.Timers.E lapsedEventArgs e)

{
this.timer.Stop ();

[...]

}
Do I have to create a thread monitor to test when those threads are
finished before allowing the service to go to the next Timer_Tick?
Jun 8 '07 #2

"John A. Bailo" <ja*****@texeme .comwrote in message
news:nq******** *************** *******@speakea sy.net...
>
From a Windows service (NET 2.0) I want to launch serveral threads in a
for loop that invokes a method using:

new Thread(delegate ()
{ myMethod(248);} ).Start();
Will those threads stay active even when the service reaches it Service
Timer Stop?
Why don't you just start the thread and at myMethod, which can be for each
thread proxy/delegate, use thread.sleep() in a While True Loop?
Do I have to create a thread monitor to test when those threads are
finished before allowing the service to go to the next Timer_Tick?
You need to have a thread monitor on a timer to make sure all threads are in
a state of thread.IsAlive.

Jun 8 '07 #3
Mr. Arnold wrote:
Why don't you just start the thread and at myMethod, which can be for
each thread proxy/delegate, use thread.sleep() in a While True Loop?
That statement is completely unclear to me.
You need to have a thread monitor on a timer to make sure all threads
are in a state of thread.IsAlive.
So are you saying that a Timer.Stop() will cause all threads launched
within the windows service to terminate or pause?

Shouln't Timer.stop(), running on the main thread, only affect the main
thread of the application?

That is the basis of my questions.

Jun 8 '07 #4
John A. Bailo wrote:
Mr. Arnold wrote:
>Why don't you just start the thread and at myMethod, which can be for
each thread proxy/delegate, use thread.sleep() in a While True Loop?


That statement is completely unclear to me.
>You need to have a thread monitor on a timer to make sure all threads
are in a state of thread.IsAlive.


So are you saying that a Timer.Stop() will cause all threads launched
within the windows service to terminate or pause?

Shouln't Timer.stop(), running on the main thread, only affect the main
thread of the application?

That is the basis of my questions.
Ok. I wrote a simple test program and answered by own question.

The answer is the threads continue to run even when the timer is running
in the background.

This is super cool stuff.

That means I can pick up items in the database (tasks) that need to be
done, and have them run on threads and let my timer/main thread continue
to chug along looking for new stuff.

If I ever want to check on completion status of threads (which I don't
in this case) I could as you suggest, set up a pool and check for
completion, etc.

Jun 8 '07 #5

"John A. Bailo" <ja*****@texeme .comwrote in message
news:46******** ******@texeme.c om...
John A. Bailo wrote:
>Mr. Arnold wrote:
>>Why don't you just start the thread and at myMethod, which can be for
each thread proxy/delegate, use thread.sleep() in a While True Loop?


That statement is completely unclear to me.
class void StartAThread() //the Thread.Start() proxy/delegate
{
try
{
While True
{
Do Something();
Thread.Sleep(wa ittime);
}
Catch ex
{
// the catch will break out of the while on thread abort
}
}
>>
>>You need to have a thread monitor on a timer to make sure all threads
are in a state of thread.IsAlive.


So are you saying that a Timer.Stop() will cause all threads launched
within the windows service to terminate or pause?
You spawn a thread and the only way it's going yo be stopped is if you use
Thread.Stop, Thread.Pause, Thread.Sleep(0) (shut it down),
Thread.Sleep(10 00) (sleep 1 second) or the thread aborts.
>>
Shouln't Timer.stop(), running on the main thread, only affect the main
thread of the application?

That is the basis of my questions.

Ok. I wrote a simple test program and answered by own question.

The answer is the threads continue to run even when the timer is running
in the background.

This is super cool stuff.

That means I can pick up items in the database (tasks) that need to be
done, and have them run on threads and let my timer/main thread continue
to chug along looking for new stuff.

If I ever want to check on completion status of threads (which I don't in
this case) I could as you suggest, set up a pool and check for completion,
etc.
You need to abandon the Timer running in the background.

http://www.yoda.arachsys.com/csharp/threads/

I read somewhere that in using threads the While True is the method to be
used in a .NET NT Service application.
>
Jun 8 '07 #6

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

Similar topics

3
3637
by: brian | last post by:
I have an ASP.Net application that uses impersonation. This works fine for accessing/executing the application. However, the app utilizes a timer, that when fired uses the <machine>ASPNET identity. In order to correct this problem I've modified the Machine.config file in the \Microsoft.Net\Framework\v1.1.4322 folder. However, this didn't solve the problem; instead of using the user id and password specified in Machine.Config, the...
0
392
by: Dan S | last post by:
I am using a third party DLL which is the interface to an off-the-shelf document management system (so I have to use it). Unfortunately it is very poor and if there is a problem with the server, calls to this DLL simply hang (on the order of 5 minutes). When this occurs that means there is a problem with the Server and I need to communicate back to the consumers of my Web Service this is the case. Basically, I need to set some kind of...
4
4448
by: JeffSinNHUSA via DotNetMonster.com | last post by:
Hi, I have a long running task that I want to run on a regular basis to do some db updates. I can't write a windows service because it is being hosted elsewhere. I want to run this task within my web application - so here is what I did: In the global.asax I declared a delegate function and a timer. In the application start event, I started the timer. I created a method to respond to the timer event, which creates a new thread and...
2
4065
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: The MyService service on Local Computer started and then stopped. Some services stop automatically if they ahve no work to do, for example, the Perforamnce Logs and Alert service. I tried switching to a System.Threading.Timer and that didn't work...
1
1736
by: Water Cooler v2 | last post by:
I have a Windows Service I am writing in C# and a set of, let us say three, other executables written in C# (mostly console applications). I want that the Windows Service must do so every few seconds: Check to see if each of the other executables are running or not. If they are not running, it should load them. For this purpose, I am planning the following:
5
12247
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the event handlers may take longer than the interval for either of the timers, so it's possible for multiple events to fire "simultaneously" and for events to queue up. I'm attempting to get the timers to sync on some reference type object, or use...
6
2120
by: cyberco | last post by:
In my wxPython app a non-GUI thread (that reads info from the network) tries to open a frame to show the new info. This results in my app hanging (which is not too surprising). Coming from a C# environment I wonder if there is some sort of delegate mechanism in wxPython to do this sort of thing. 2B
5
2180
by: Jeff | last post by:
Hey ..NET 2.0 I'm working on a winservice created in .NET 2.0. Now I want to do some modications to this winservice. I want this winservice at every start of a new month to start a thread which pulls data from several webservices and saves these data to table... So I'm wondering how to go about implementing this so that this thread is
0
935
by: zb | last post by:
Problem: I am implementing my design and the implementation is erroring out in multithread scenario. And, I lack expertise in multith read arena. You expert opinion is sought. Scenario: I have a windows service that is suppose to pick configuration information from a XML file (NOT app.config). First time the service is started info config files are read and
0
8991
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
9544
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
9247
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
8243
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...
1
6796
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
6074
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
4606
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...
1
3313
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
3
2215
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.