M
Muki Rapp
Hi!
In the example below, once the media is full, the FileSteam.WriteByte throws
an exception and the code
is designed to handle it. However, when the GC is invoked, it calls the
Finalize of FileSteam, who is trying
to flush and close the stream, but the disk is full, so the flush fails and
another exception is thrown from another
(GC) thread. An ugly solution would be to use GC.SuppressFinalize(fs).
Is there a better solution or good practice? (closing withot flushing
perhaps)?
many thanks,
M. Rapp
--------------------------------
Example:
static void Main(string[] args)
{
try
{
FileStream fs =
new FileStream(args[0], FileMode.Create);
Console.WriteLine("starting to write...");
while (true)
fs.WriteByte(0xff);
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}",
e.Message);
}
Console.WriteLine("press any key to continue");
Console.Read();
}
In the example below, once the media is full, the FileSteam.WriteByte throws
an exception and the code
is designed to handle it. However, when the GC is invoked, it calls the
Finalize of FileSteam, who is trying
to flush and close the stream, but the disk is full, so the flush fails and
another exception is thrown from another
(GC) thread. An ugly solution would be to use GC.SuppressFinalize(fs).
Is there a better solution or good practice? (closing withot flushing
perhaps)?
many thanks,
M. Rapp
--------------------------------
Example:
static void Main(string[] args)
{
try
{
FileStream fs =
new FileStream(args[0], FileMode.Create);
Console.WriteLine("starting to write...");
while (true)
fs.WriteByte(0xff);
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}",
e.Message);
}
Console.WriteLine("press any key to continue");
Console.Read();
}