Any way to open a FileStream asynchronously?

G

Guest

Is there any way to perform the open of a .NET 1.1 FileStream object
asynchrously? My app must open hundreds of files, and I need to reduce the
"blocked" time waiting for these opens to complete. I've considered
performing the open on a separate thread, but that gets complicated in a
hurry.

BTW: I know there is a way to open a FileStream so that it supports async
reads/writes. But that's not what I need to do... I want to perform the open
of the filestream asynchronously, and then perform synchronous reads/writes.

Thanks!

D
 
T

The Grim Reaper

Unfortunately, I think threading is the only way to go....
Look at it this way - if I can get the hang of it, so can you!!
_______________________________
The Grim Reaper
 
R

Roman Wagner

Be careful when opening "hundreds" of files asynchronously! In worst
case u will have "hundreds" of parallel threads accessing your
filesystem, thats not good.
--> Limit the maximum number of threads working.
 
D

David Cartwright

David said:
Is there any way to perform the open of a .NET 1.1 FileStream object
asynchrously? My app must open hundreds of files, and I need to reduce
the
"blocked" time waiting for these opens to complete. I've considered
performing the open on a separate thread, but that gets complicated in a
hurry.

I think you're going to have to go down the multi-threading route. But don't
be scared! Threads look scary the first time you use them, but once you've
figured them out you wonder why you ever found them tricky.

David C
 
J

Jon Skeet [C# MVP]

David Cartwright said:
I think you're going to have to go down the multi-threading route. But don't
be scared! Threads look scary the first time you use them, but once you've
figured them out you wonder why you ever found them tricky.

I don't know about that. I've been using threads (and writing about
them) for years and I still find them scary and tricky. Getting a
multi-threaded program absolutely right can be very, very difficult,
especially in the face of a memory model implementation which may be
doing much more optimisation than you expect it to.
 

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