Start a new thread from an existing thread, which was started from atimer

C

Curious

Hi,

It turns out that I must start a new thread from an existing thread
that was started from a timer.

In other words, the relations are described in the code below:

void Main()
{

mTimer = new Timer(new TimerCallback(CheckHistoricalData), null,
15000, 15000);

}

// Callback for the timer
void CheckHistoricalData(object state)
{

ThreadPool.QueueUserWorkItem(new WaitCallback(GetCashByList), null);

// Code omitted here
}

void GetCashByList(object o)
{

// Code omitted here
if (cashR.CashForToday <= cashR.LowerBound)
{

// Start a new thread to display messagebox
// Pass both list and cash for sector
ThreadPool.QueueUserWorkItem(new WaitCallback
(ShowSectorCashMessage), cashR);

}
}

I'm concerned that my program may crash because each thread is at a
different level and there are so many levels of threads. Anyone can
advice me if this is safe? Is there anything I can do to make the
program robust?
 
J

Jon Skeet [C# MVP]

Curious said:
It turns out that I must start a new thread from an existing thread
that was started from a timer.

In other words, the relations are described in the code below:

I'm concerned that my program may crash because each thread is at a
different level and there are so many levels of threads. Anyone can
advice me if this is safe? Is there anything I can do to make the
program robust?

There's no such thing as a thread "level". There are just threads -
admittedly there are threads in the thread-pool and threads which
aren't in the thread-pool, but I see nothing in the code you've posted
which will crash the system. You should look at whether you *really*
need all those threads though, just for the sake of understanding the
complexity of the system.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top