Home All Groups Group Topic Archive Search About

Start a new thread On demand

Author
2 Aug 2006 5:00 PM
Mohammad Hashemian
Hello,
I'm writing an application that has a main thread. If some special data
arrives from a port, main thread should execute special function in a
new thread rapidly (at most with 500 miliseconds delay).
I used the regular .NET threading system, but in most cases, the second
thread doesn't execute even in 50 seconds.
How can I start a new thread that it'll be executed at once?
thanks.

Author
2 Aug 2006 6:13 PM
Greg Young
It doesn't start executing within 50 seconds or it doesn't finish?

How are yous tarting this other thread (Thread.Start() ? queuing the item in
the thread pool?)

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

Show quote
"Mohammad Hashemian" <m.hashem***@gmail.com> wrote in message
news:1154538050.939405.83420@s13g2000cwa.googlegroups.com...
> Hello,
> I'm writing an application that has a main thread. If some special data
> arrives from a port, main thread should execute special function in a
> new thread rapidly (at most with 500 miliseconds delay).
> I used the regular .NET threading system, but in most cases, the second
> thread doesn't execute even in 50 seconds.
> How can I start a new thread that it'll be executed at once?
> thanks.
>
Author
2 Aug 2006 6:57 PM
Jon Skeet [C# MVP]
Mohammad  Hashemian <m.hashem***@gmail.com> wrote:
> I'm writing an application that has a main thread. If some special data
> arrives from a port, main thread should execute special function in a
> new thread rapidly (at most with 500 miliseconds delay).
> I used the regular .NET threading system, but in most cases, the second
> thread doesn't execute even in 50 seconds.
> How can I start a new thread that it'll be executed at once?

I find it hard to believe that the new thread doesn't start in under 50
seconds unless you've hammered the system beyond the point of sanity.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.


--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
3 Aug 2006 2:44 AM
Mohammad Hashemian
here is the part of code that starts a new thread:

if(!dataReceptionThread)
    dataReceptionThread = gcnew Thread(
                          gcnew
ParameterizedThreadStart(Machine::DataReception));
dataReceptionThread->Name = "RtdataReceptionThread";
dataReceptionThread->Priority = ThreadPriority::Highest;
Process::Start(Machine::RealTimeExePath);
Machine::baseTime = DateTime::Now;
dataReceptionThread->Start(result);
Thread::CurrentThread->Sleep(500);
if(!dataReceptionThread->IsAlive)
    throwgcnew Exception("Thread didn't run yet!");
Author
3 Aug 2006 5:00 AM
Jon Skeet [C# MVP]
Mohammad  Hashemian <m.hashem***@gmail.com> wrote:
> here is the part of code that starts a new thread:

Please see http://www.pobox.com/~skeet/csharp/incomplete.html

Note that Thread.Sleep is a static method - it *always* applies to the
current thread, contrary to what the casual reader of

Thread::CurrentThread->Sleep(500);

would anticipate.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
3 Aug 2006 1:48 PM
Mohammad Hashemian
Thanks all,
The problem was in another function that was executed in another
thread. That function caused this thread ends early.
By the way, thanks for your attention.

AddThis Social Bookmark Button