473,386 Members | 2,129 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,386 software developers and data experts.

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 ConnectionString, int Id, DateTime
ScheduleDate)
{
_now = DateTime.Now;
_connectionString = ConnectionString;
_intSleep =
Convert.ToInt32(((TimeSpan)ScheduleDate.Subtract(_ now)).TotalMilliseconds);

_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(string ConnectionString, int Id, DateTime
ScheduleDate)
{
//That's exactly my question (???)
}
---------------------------------

Nov 18 '05 #1
1 1709
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.Threading.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 ConnectionString, int Id, DateTime
ScheduleDate)
{
_now = DateTime.Now;
_connectionString = ConnectionString;
_intSleep =
Convert.ToInt32(((TimeSpan)ScheduleDate.Subtract( _now)).TotalMilliseconds);

_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(string ConnectionString, 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
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...
2
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....
2
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...
6
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...
8
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...
2
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...
3
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...
35
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...
16
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...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
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...

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.