Connecting Tech Pros Worldwide Help | Site Map

Share Process

Member
 
Join Date: Oct 2006
Posts: 96
#1: 3 Weeks Ago
Hello all,

I am developing a application in c#.NET for Windows CE 5.0 device.
1) Need to process some information - Which is i am doing fine no problem.
2) I need to record some data into a one file in continuosly.

My problem is writting data into file is killing the process time. For one cycle processing time is around 180 ms to write. So i decided to use reflections which use another exe to write the data into a file continulosly.

But the type.invokemember() function is not supporting for Windows CE 5.0.

I am using .NET Compact Frame work 2.0.

My ultimate aim is to complete the file write process with in 10 ms. (only for file write). Could you please suggest some idea to implement this.

Thanks in advance.
Rajesh G
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#2: 3 Weeks Ago

re: Share Process


How much data are you writting?
What is the media you are writing to?

You can *want* to write 500mb in 10ms for example, but you can't do better than the drive is capable of.
Member
 
Join Date: Oct 2006
Posts: 96
#3: 3 Weeks Ago

re: Share Process


I am using USB 2.0 Speed flash memory. I am writting 500bytes of information into a file for every 10ms. I hope the 2.0 is better speed to achive wrtting data with in 10ms.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#4: 3 Weeks Ago

re: Share Process


Unlikely.
Keep in mind:
For your 500 bytes of data there is probably more than 500bytes in communication overhead to open and close the file.
Flash drives are netoriously slow when writing. They are faster when reading.
Flash memory is rated for a limited number of writes. They will fail and their lifespan is not as long as a hard drive.

I might suggest a scheme were you write to a class every 10ms and have that class hold the data. Then after every 50 lines of input, write that to the flash memory on a separate thread. Now you still record all your data at 10ms, but you are only writing every 500ms.
Member
 
Join Date: Oct 2006
Posts: 96
#5: 3 Weeks Ago

re: Share Process


I measured the file write() will write the data into a file with in 2ms but file flush function is consuming more time to save the contents. The auto flush = true is calling flush function after every filewrite.
Is there any way to save the file without calling file flush?
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#6: 3 Weeks Ago

re: Share Process


Can I see your file write routine?
Member
 
Join Date: Oct 2006
Posts: 96
#7: 3 Weeks Ago

re: Share Process


Expand|Select|Wrap|Line Numbers
  1. public partial class Form1 : Form
  2.     {
  3.         public long Start_Tick_Count = 0;
  4.         public long End_Tick_Count = 0;
  5.         DateTime SystemDate;
  6.         public string data = "";
  7.         int Count = 0;
  8.         TextWriter TextFile = new StreamWriter("File1.txt");    
  9.  
  10.         public Form1()
  11.         {
  12.             InitializeComponent();
  13.         }
  14.  
  15.         private void button1_Click(object sender, EventArgs e)
  16.         {
  17.  
  18.             Application.Exit();  
  19.         }
  20.  
  21.         private void Form1_Load(object sender, EventArgs e)
  22.         {
  23.            SystemDate = DateTime.Now;
  24.  
  25.         }
  26.  
  27.         private void timer1_Tick_1(object sender, EventArgs e)
  28.         {
  29.             int Index = 0;
  30.             Start_Tick_Count = System.Environment.TickCount;
  31.             listBox1.Items.Add(Convert.ToString(Start_Tick_Count - End_Tick_Count));
  32.             SystemDate = SystemDate.AddMilliseconds(Start_Tick_Count - End_Tick_Count);
  33.             End_Tick_Count = System.Environment.TickCount;
  34.  
  35.             for (Index = 0; Index <= 256; Index++)
  36.             {
  37.                 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");
  38.                 data = label1.Text;
  39.                 TextFile.WriteLine(data);  
  40.                 //TextFile.Flush(); 
  41.             }
  42.  
  43.             if (Count > 19)
  44.             {
  45.                 Count = 0;
  46.                 TextFile.Flush(); 
  47.             }
  48.             else
  49.                 Count = Count + 1;
  50.  
  51.         }
  52.  
  53.  
  54.     }
  55. }
In the above application, while executing the file flush function the application processing time increases.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#8: 3 Weeks Ago

re: Share Process


TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,745
#9: 3 Weeks Ago

re: Share Process


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?
Expand|Select|Wrap|Line Numbers
  1. for (Index = 0; Index <= 256; Index++)
  2.             {
  3.                 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");
  4.                 data = label1.Text;
  5.                 TextFile.WriteLine(data);  
  6.                 //TextFile.Flush(); 
  7.             }
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.
Expand|Select|Wrap|Line Numbers
  1. DateTime pModDate = DateTime.Now;
  2. szEntryText = string.Format("{0}\t{1}\t{2}",
  3.                             pModDate.ToString("ddMMMyy"),
  4.                             pModDate.ToString("HH:mm:ss.fff"),
  5.                             szEntryText);
  6. // Date {tab} time {tab} entrytext
  7.  
  8. try
  9. {
  10.     using (FileStream fs = new FileStream(szFileName, FileMode.Append))
  11.     {
  12.         //Encoding isoWesternEuropean = Encoding.GetEncoding(28591);
  13.         //using (StreamWriter w = new StreamWriter(fs, isoWesternEuropean))
  14.         using (StreamWriter w = new StreamWriter(fs, Encoding.Unicode))
  15.         {
  16.             w.WriteLine(szEntryText);
  17.             //w.Close(); // bad
  18.             Console.WriteLine(szEntryText);// For running from Visual Studio debugger
  19.         } // end using StreamWriter
  20.         //fs.Close(); // bad
  21.     }// End using FileStream
  22.     // w and fs now out of scope therefore
  23. } // end try
  24.  
  25. catch (Exception err)
  26. {
  27.     Console.WriteLine("Log write error: " + err.Message);
  28. }
  29. // Both FileStream and StreamWriter close themselves when they fall out of scope of their respective using statement
  30.  
Member
 
Join Date: Oct 2006
Posts: 96
#10: 3 Weeks Ago

re: Share Process


You sugesstion is valuable. But that doesnt save any process time. So thats the reason i want to run another process. I will transfer the information to write through main process. Like in reflection. Even i tried in threads doesnt save any processing time.
Reply