I am using C#.NET 1.1, however it would appear that my problem may be with any release of the .NET Famework (so, 2.0 also, as I think 3.0 and 3.5 use the same base library as 2.0).
My problem is that when I issue a simple BeginRead() off of a Stream variable (in System.IO), the method blocks until the entire file is read. The arguments for BeginRead are in the code block below. I pass in my byte buffer, an offset of 0, the length of my buffer, my callback method, and in this case I'm using null for object state, which is perfectly valid. It _does_ read, so it works, it just doesn't continue on as it's supposed to.
If I call BeginRead off my Stream var and then immediately issue a Console.WriteLine("This line right after BeginRead call!!"), I don''t receive the Console.WriteLine until -after- the entire read process has completed. I've tried this with changing the size of the byte buffer and the size of the file, I've even put the file on an external drive and given a buffer length of like 1 but to no avail. Actually with a large file (~200MB) and a byte buffer length of 1 I get a Fatal Stack Overflow error and the program throws.
Simple C# program. Ideas? Am I misunderstanding the idea of BeginRead's state object here, or what is going on? I've done a bit of digging and this does appear to be the appropriate use. Also I've encountered training documentation which says not only that this is the way to do it but also that until you issue an EndRead(), you won't get a block (EndRead() apparently blocks until the file is done reading, but I wouldn't know as my BeginRead() is blocking). One other interesting thing to note is that I get multiple calls to my callback method. Help!
// Signature for BeginRead()
public virtual IAsyncResult BeginRead(