You said you were writing data every 10ms.
You are really doing MORE than just writing data. Much of which seems pointless to me.
What I don't see is any *data* being passed or written. Just the time.
A loop that seems to do nothing more than count to 255, writing a line every time?
- for (Index = 0; Index <= 256; Index++)
-
{
-
label1.Text = SystemDate.ToString("yyyy-MM-dd-hh:mm:ss:fff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");
-
data = label1.Text;
-
TextFile.WriteLine(data);
-
//TextFile.Flush();
-
}
What's all the zeros in the DateTime format?
Is there a reason you are setting all this into a label then getting it back out again before writing it to your file? Labels are not fast controls.
As for the actual writing part... I've never used TextWriter so I can't tell you if it is good/bad or otherwise.
Here is (part of) how I write my log files to hard drive:
string szEntryText is the text parameter passed into the method further up than shown here.
-
DateTime pModDate = DateTime.Now;
-
szEntryText = string.Format("{0}\t{1}\t{2}",
-
pModDate.ToString("ddMMMyy"),
-
pModDate.ToString("HH:mm:ss.fff"),
-
szEntryText);
-
// Date {tab} time {tab} entrytext
-
-
try
-
{
-
using (FileStream fs = new FileStream(szFileName, FileMode.Append))
-
{
-
//Encoding isoWesternEuropean = Encoding.GetEncoding(28591);
-
//using (StreamWriter w = new StreamWriter(fs, isoWesternEuropean))
-
using (StreamWriter w = new StreamWriter(fs, Encoding.Unicode))
-
{
-
w.WriteLine(szEntryText);
-
//w.Close(); // bad
-
Console.WriteLine(szEntryText);// For running from Visual Studio debugger
-
} // end using StreamWriter
-
//fs.Close(); // bad
-
}// End using FileStream
-
// w and fs now out of scope therefore
-
} // end try
-
-
catch (Exception err)
-
{
-
Console.WriteLine("Log write error: " + err.Message);
-
}
-
// Both FileStream and StreamWriter close themselves when they fall out of scope of their respective using statement
-