Start a new thread On demand

  • Thread starter Thread starter Mohammad Hashemian
  • Start date Start date
M

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.
 
Mohammad Hashemian said:
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.
 
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!");
 
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.
 
Back
Top