Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

FileStream Write blocks multi threaded app

FileStream Write SD problem

  • Please log in to reply
2 replies to this topic

#1 366cobra

366cobra

    Member

  • Members
  • PipPip
  • 16 posts

Posted 20 August 2014 - 11:18 AM

Hi,

 

I have updated my NP2 to 4.3.1 about 3 weeks ago and also upgraded my app to .NET 4.3.

Now I am noticing that the file write seems to kill the whole app.

 

The app is multi threaded, reading different sensors, which write the data to a file.

i am using the file as a buffer, as the network may be cut, but the app should not miss any readings.

 

The write is inside a lock, so the threads will not be able to use the same file obj at the same time.

I open the file once in a singleton obj and use it to write and flush the data to file.

Since there is a lot of data going into the file, I do not want to open, wite, flush and close it all the time.

The app can log dozens of readings per sec.

 

Below is the line where the file gets opened and below that how the data get written to the file.

The last log that is printed is "WriteToFile lock" and after that the whole app just dies.

All thread seem to get blocked.

I would expect multiple "WriteToFile begin" lines, until all thread are stuck at the "WriteToFile begin"

e.g.

 

WriteToFile begin

WriteToFile lock

WriteToFile begin

WriteToFile begin

WriteToFile begin

WriteToFile begin

m_oWriteFile = new FileStream(m_sLogFileName, FileMode.OpenOrCreate, FileAccess.Write);
   protected void WriteToFile(byte[] a_sData)
   {
      Debug.Print("WriteToFile begin");
      lock (m_oFileLock)
      {
         Debug.Print("WriteToFile lock");
         try
         {
            if (m_oWriteFile != null)
            {
               m_oWriteFile.Write(a_sData, 0, a_sData.Length);
               m_oWriteFile.Flush();
            }
         }
         catch (Exception ex)
         {
            Debug.Print("EXCEPTION: CSdCard:WriteToFile - " + (ex.InnerException == null ? ex.Message : ex.InnerException.Message));
         }
      }
      Debug.Print("WriteToFile end");
   }

With an older firmware version the code above worked fine.

Has anyone got an idea what this could be?

Bug in 4.3.1?

 


Can't wait for my Agent watch to arrive..........


#2 366cobra

366cobra

    Member

  • Members
  • PipPip
  • 16 posts

Posted 20 August 2014 - 12:19 PM

have changed

m_oWriteFile.Flush();

to

VolumeInfo.GetVolumes()[0].FlushAll();

and the app has been running at least twice as long as before.

will see if it still runs after hours.


Can't wait for my Agent watch to arrive..........


#3 366cobra

366cobra

    Member

  • Members
  • PipPip
  • 16 posts

Posted 21 August 2014 - 11:03 AM

Not a nice workaround, but It seems all good now.


Can't wait for my Agent watch to arrive..........





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.