SE problems with storage card removal and open files

D

Drak

I just bought a new Axim x50v and tested my application on it - spent
some time to fix the disappearing toolbar icons and other minor
problems. However I can not find any information regarding the
following problem:

1. I open a file located on a storage card using System.IO.FileStream.
2. Remove the storage card
3. Any operation on the stream (e.g. Seek or ReadByte) will hang the
program - the program never gets the control after calling Seek or
ReadByte
On my older (2002) device the above will throw an exception (which is
the expected behavior).

Here is the sample code I run (just adjust the path - use any file you
want):

try
{
System.IO.FileStream s =
new System.IO.FileStream(@"\SD Card\Test.tst",
System.IO.FileMode.Open,
System.IO.FileAccess.Read, System.IO.FileShare.Read, 15000,
false);

MessageBox.Show("remove the card now");

s.ReadByte(); //or call -> s.Seek(1, System.IO.SeekOrigin.Begin);

MessageBox.Show("never comes here");
}
catch
{
MessageBox.Show("never comes here either");
}
 
D

Dan Bass

Could you not check the path exists before performing the read?
When a card is removed then Directory.Exists(@"\SD Card") would presumably
return false...
 
D

Drak

OK, good idea - I tried it and it helps in 2/3 of the cases. Here is
the new problem: I remove the card for 5-10 seconds, then put it back
in and then do the read - it hangs again and the suggested check does
not help because the directory actually exists in this case.

It seems that the netcf FileStream object does not handle the scenario
when the underlying file handle is automatically closed on a lower
(system) level in the case when the card is removed.

Any ideas for a solution or a workaround that will reduce the
possibility of this to happen will be greatly appreciated.

Thanks
 
D

Dan Bass

I'm not too surprised that happens...

Out of interest, why don't you minimize the opportunity for this to happen
by creating the file stream, reading all the data from the file into a
buffer and closing the file stream again one command after the other.

Then any time you need the data, you can access the in memory buffer rather
than the FileStream.
 
D

Drak

Out of interest, why don't you minimize the opportunity for this to happen
by creating the file stream, reading all the data from the file into a
buffer and closing the file stream again one command after the other.

Then any time you need the data, you can access the in memory buffer rather
than the FileStream.

The file is really big - that's why to handle memory cards correctly
is so important - the memory card is the most likely location for such
big files. The average size is 4-6MB, some reaching 15-20MB. I thought
of closing the file after every operation and then opening it again
when I need it but this introduces problems like locking etc. - I can
not be sure that the file will be the same the next time I open it...

I do not know whether this is an Axim problem or a 2003SE problem.
The latest netcf version is not the problem I think because it is OK
on my 2002 device. If it is just the Axim - I can probably ignore it
and wait for a patch from Dell. If it is 2003SE - too bad :(.

Any ideas?

Thanks again,

M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top