473,799 Members | 2,997 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to manage multiple threads

Hi all

I am new to threading!

I am developping a newsletter tool including a dispatch manager that
should schedule sendings. The Web layer kicks a remote object hosted by
a windows service and should 'add' a schedule (time to send, id and so
on). The result should be that I have multiple threads waiting for the
send time (with thread.sleep). Now the question: How can I abort or
change the 'time to send' if the web administrator changes the (already
scheduled) send time? In other words: How can I refer one of my already
thrown threads. Please refer to the threading question only because the
surrounding behaviour (like architecture and so on) is already given.

Thank you so much for an idea how to refer thrown threads.

For a better understanding of my question a code snipplet that - did I
mention it? - is a first try with threading:

---------------------------------
public void Schedule(string ConnectionStrin g, int Id, DateTime
ScheduleDate)
{
_now = DateTime.Now;
_connectionStri ng = ConnectionStrin g;
_intSleep =
Convert.ToInt32 (((TimeSpan)Sch eduleDate.Subtr act(_now)).Tota lMilliseconds);

_id = Id;

Thread t = new Thread(new ThreadStart (RunThread));
t.Start();
}

private void RunThread()
{
if (_intSleep > 0) {Thread.Sleep(_ intSleep);}
//... Send the threaded Newsletter somehow ...
}

public void ClearSchedule(s tring ConnectionStrin g, int Id, DateTime
ScheduleDate)
{
//That's exactly my question (???)
}
---------------------------------

Nov 18 '05 #1
1 1720
Hi Raoul:

I think you should reconsider the threading approach you are using. If
someone wants a newsletter to go out 2 days from now - do you expect
the thread to sleep for two days? What if the server is reset during
that time? There are some drawbacks to this approach.

Consider this alternative: Keep the scheduled times to send a
newsletter in a collection. The more durable collection, the better.
You could use an ArrayList, but even better would be an XML file
(because it would survive server restarts), and even better still a
database table (because it takes care of atomic operations for you).

You could then use a thread and a System.Threadin g.Timer class to
periodically wake up a thread with an event (say every 10 seconds,
every 60 seconds, every 10 minutes, depending on how granular and
precise the send needs to be) which can check the collection and send
out newsletters (perhaps on a second thread).

You will use fewer threads, and have a more robust approach. In
addition, changing an existing schedule doesn't involve signaling or
interrupting a waiting thread, it's just changing a record in the
database.

HTH,

--
Scott
http://www.OdeToCode.com/

n Sat, 02 Oct 2004 01:07:12 +0200, Raoul Minder
<ra*****@please .no.spam.gmx.ch > wrote:
Hi all

I am new to threading!

I am developping a newsletter tool including a dispatch manager that
should schedule sendings. The Web layer kicks a remote object hosted by
a windows service and should 'add' a schedule (time to send, id and so
on). The result should be that I have multiple threads waiting for the
send time (with thread.sleep). Now the question: How can I abort or
change the 'time to send' if the web administrator changes the (already
scheduled) send time? In other words: How can I refer one of my already
thrown threads. Please refer to the threading question only because the
surrounding behaviour (like architecture and so on) is already given.

Thank you so much for an idea how to refer thrown threads.

For a better understanding of my question a code snipplet that - did I
mention it? - is a first try with threading:

---------------------------------
public void Schedule(string ConnectionStrin g, int Id, DateTime
ScheduleDate )
{
_now = DateTime.Now;
_connectionStri ng = ConnectionStrin g;
_intSleep =
Convert.ToInt3 2(((TimeSpan)Sc heduleDate.Subt ract(_now)).Tot alMilliseconds) ;

_id = Id;

Thread t = new Thread(new ThreadStart (RunThread));
t.Start();
}

private void RunThread()
{
if (_intSleep > 0) {Thread.Sleep(_ intSleep);}
//... Send the threaded Newsletter somehow ...
}

public void ClearSchedule(s tring ConnectionStrin g, int Id, DateTime
ScheduleDate )
{
//That's exactly my question (???)
}
---------------------------------


Nov 18 '05 #2

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

Similar topics

7
11219
by: Guyon Morée | last post by:
If I have multiple threads reading from the same file, would that be a problem? if yes, how would I solve it? Let's say I want to take it a step further and start writing to 1 file form multiple threads, how would I solve that? thanx,
2
2670
by: Joe | last post by:
Hey, I'm going to give some background on my situation in case anyone can point out a way around my problem altogether... for the problem itself, please skip to the bottom of the post. thanks. I've been having some problems with database performance... Several threads are constantly attempting INSERTs of new records into a large table - that is hundreds of thousands of records -large by my account :-) The table has a VARCHAR field...
2
2104
by: Tumurbaatar S. | last post by:
ASP.NET QuickStart Tutorial says that: .... ASP.NET maintains a pool of HttpApplication instances over the course of a Web application's lifetime. ASP.NET automatically assigns one of these instances to process each incoming HTTP request that is received by the application. The particular HttpApplication instance assigned is responsible for managing the entire lifetime of the request and is reused only after the request has been...
6
5001
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
8
1811
by: Manfred Braun | last post by:
Hello All! I am writing a management application, which has to access remote machines registry via System.Diagnostics.EventLog.CreateEventSource . For each machine, I connect to, I create a DirectoryEntry and connect to that machine specifying credentials. That's becauase the running user does not has the right permissions . The application is written in C# and the action taken is done with threads from the threadpool.
2
2323
by: Brett | last post by:
What are the advantages/disadvantages of using one process with multiple threads or doing the same task with multiple processes, each having one thread? I see using multiple threads under one process as being a problem. Potentially, one thread may crash and could bring down the whole process, including all the other threads. Using one process per thread seems more independent. This is similar to what happens when you open multiple...
3
8451
by: ian_jacobsen | last post by:
First let me start by saying that this problem is not consistently reproducible. I have a windows service that creates reports for a group of entities. This service can process multiple groups at a single time, where each group is running in a separate thread. I have noticed mixed behavior when running multiple groups at one time (in separate threads). I have received the following two messages logged as errors. - A Crystal Reports...
35
9367
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from 500000 to 3200000 of a file whose size is say 20MB... how do i request a download which starts directly at 500000th byte... thank u cheers
16
15571
by: WATYF | last post by:
Hi there... I have a huge text file that needs to be processed. At the moment, I'm loading it into memory in small chunks (x amount of lines) and processing it that way. I'd like the process to be faster, so I'd like to try creating multiple threads, and having them load different chunks of the file at the same time and process it asynchronously. Is it possible to do something like that, and if so, what would be needed to do so?
0
9687
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
9541
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
10252
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10231
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9073
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
7565
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
5463
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...
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
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.