Share Process

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajesh6695
    New Member
    • Oct 2006
    • 96

    Share Process

    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.invokememb er() 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
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    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.

    Comment

    • rajesh6695
      New Member
      • Oct 2006
      • 96

      #3
      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.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        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.

        Comment

        • rajesh6695
          New Member
          • Oct 2006
          • 96

          #5
          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?

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Can I see your file write routine?

            Comment

            • rajesh6695
              New Member
              • Oct 2006
              • 96

              #7
              Code:
              public partial class Form1 : Form
                  {
                      public long Start_Tick_Count = 0;
                      public long End_Tick_Count = 0;
                      DateTime SystemDate;
                      public string data = "";
                      int Count = 0;
                      TextWriter TextFile = new StreamWriter("File1.txt");    
              
                      public Form1()
                      {
                          InitializeComponent();
                      }
              
                      private void button1_Click(object sender, EventArgs e)
                      {
              
                          Application.Exit();  
                      }
              
                      private void Form1_Load(object sender, EventArgs e)
                      {
                         SystemDate = DateTime.Now;
                         
                      }
              
                      private void timer1_Tick_1(object sender, EventArgs e)
                      {
                          int Index = 0;
                          Start_Tick_Count = System.Environment.TickCount;
                          listBox1.Items.Add(Convert.ToString(Start_Tick_Count - End_Tick_Count));
                          SystemDate = SystemDate.AddMilliseconds(Start_Tick_Count - End_Tick_Count);
                          End_Tick_Count = System.Environment.TickCount;
              
                          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(); 
                          }
              
                          if (Count > 19)
                          {
                              Count = 0;
                              TextFile.Flush(); 
                          }
                          else
                              Count = Count + 1;
              
                      }
              
              
                  }
              }
              In the above application, while executing the file flush function the application processing time increases.
              Last edited by tlhintoq; Oct 27 '09, 10:12 AM. Reason: [CODE] ...your code here...[/CODE] tags added

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                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.

                Comment

                • tlhintoq
                  Recognized Expert Specialist
                  • Mar 2008
                  • 3532

                  #9
                  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?
                  Code:
                  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.
                  Code:
                  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

                  Comment

                  • rajesh6695
                    New Member
                    • Oct 2006
                    • 96

                    #10
                    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.

                    Comment

                    Working...