Hi guys
Please dont make my fun,this is first time i am using threading in my code.
From following code I am expecting to write current time using
DateTime::Now (hh:mm::ss::ffffff)
But my problem is that I am seeing around 20 ms difference between two write. Why ??
Shouldn't it run continuesly with the speed of CPU (i.e. 2.6 Ghz in my PC)
I am posting part of the code ,I removed some useless text box codes.
and windows initialization is also removed .
Please have look and please reply
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
ThreadStart *myThreadDelegate = new ThreadStart(this , dataReader);
trdTimer = new Thread (myThreadDelegate);
trdTimer->IsBackground = true;
trdTimer->Priority = ThreadPriority::Highest;
trdTimer->Start();
btn1->Enabled = false;
btn2->Enabled = true;
}
private: void dataReader()
{
while(true)
FileInfo *fleData = new FileInfo(S"Data.txt");
StreamWriter *swrSample;
if( fleData->Exists == true )
swrSample = fleData->AppendText();
else // Otherwise, create a new file
swrSample = fleData->CreateText();
swrSample->WriteLine( DateTime::Now.ToString("hh:mm:ss:ffffff"));
Thread::Sleep(0);
swrSample->Flush();
swrSample->Close();
}
}
private: System::Void btn2_Click(System::Object * sender, System::EventArgs * e)
{
trdTimer->Abort();
btn1->Enabled = true;
btn2->Enabled = false;
}
};
}
Please dont make my fun,this is first time i am using threading in my code.
From following code I am expecting to write current time using
DateTime::Now (hh:mm::ss::ffffff)
But my problem is that I am seeing around 20 ms difference between two write. Why ??
Shouldn't it run continuesly with the speed of CPU (i.e. 2.6 Ghz in my PC)
I am posting part of the code ,I removed some useless text box codes.
and windows initialization is also removed .
Please have look and please reply
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
ThreadStart *myThreadDelegate = new ThreadStart(this , dataReader);
trdTimer = new Thread (myThreadDelegate);
trdTimer->IsBackground = true;
trdTimer->Priority = ThreadPriority::Highest;
trdTimer->Start();
btn1->Enabled = false;
btn2->Enabled = true;
}
private: void dataReader()
{
while(true)
FileInfo *fleData = new FileInfo(S"Data.txt");
StreamWriter *swrSample;
if( fleData->Exists == true )
swrSample = fleData->AppendText();
else // Otherwise, create a new file
swrSample = fleData->CreateText();
swrSample->WriteLine( DateTime::Now.ToString("hh:mm:ss:ffffff"));
Thread::Sleep(0);
swrSample->Flush();
swrSample->Close();
}
}
private: System::Void btn2_Click(System::Object * sender, System::EventArgs * e)
{
trdTimer->Abort();
btn1->Enabled = true;
btn2->Enabled = false;
}
};
}