|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Start a new thread On demandHello,
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. 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. > Mohammad Hashemian <m.hashem***@gmail.com> wrote:
> I'm writing an application that has a main thread. If some special data I find it hard to believe that the new thread doesn't start in under 50 > 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? 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 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!"); 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.htmlNote 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 |
|||||||||||||||||||||||