Asynchronous I/O : Asynchronous Input Output : File Directory Stream C# Examples


C# Examples » File Directory Stream » Asynchronous Input Output »

 

Asynchronous I/O









    
using  System;
using  System.IO;
using  System.Windows.Forms;

class  MainClass
{
    private  static  FileStream  inStream;

    static  void  OnComplete(IAsyncResult  asyncResult)
    {
        int  bytesRead  =  inStream.EndRead(asyncResult);
        Console.Write(bytesRead);
    }

    public  static  void  Main()  
    {
        inStream  =  new  FileStream("C:\\text.txt",  FileMode.Open,  FileAccess.Read,  FileShare.None,  2048,  true);

        AsyncCallback    acb  =  new  AsyncCallback(OnComplete);

        byte[]  buf  =  new  byte[50];
        
        inStream.BeginRead(buf,  0,  50,  acb,  null);

        for(int  i=0;  i<10;  i++)
            Console.WriteLine(i);

        Console.WriteLine("Press  Enter  to  exit");
        int  resp  =  Console.Read();
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo File Directory Stream
» Asynchronous Input Output