Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

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

Reply
 
Old 06-12-2008   #1 (permalink)
Curious


 
 

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

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?

My System SpecsSystem Spec
Old 06-13-2008   #2 (permalink)
Jon Skeet [C# MVP]


 
 

Re: Start a new thread from an existing thread, which was started from a timer

Curious <fir5tsight@xxxxxx> wrote:
Quote:

> 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:
<snip>
Quote:

> 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.

--
Jon Skeet - <skeet@xxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How do the current thread get thread notification of OS intruption .NET General
thread General Discussion
start System.Threading.Thread PowerShell
Where is my thread? Vista music pictures video


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46