March 2004
Intermediate to advanced
560 pages
26h 47m
English
using System; using System.IO; using System.Text; using System.Threading; namespace Samples { public class AsyncCallBackSample { const int limit = 512; const int readlimit = 15; public class StateHolder { public byte[] bytes ; public FileStream fs ; } public static void Main() { string s = "filestream.txt"; FileStream fs = new FileStream(s, FileMode.Open, FileAccess.Read); StateHolder sh = new StateHolder(); sh.fs = fs; sh.bytes = new Byte[limit]; AsyncCallback ac = new AsyncCallback(CallMe); fs.BeginRead(sh.bytes, 0, readlimit, ac, sh); Thread.Sleep(2000); Console.WriteLine(); Console.WriteLine("Finishing Main()"); } public static void CallMe(IAsyncResult asyncResult) { StateHolder sh = (StateHolder) asyncResult.AsyncState; FileStream ...Read now
Unlock full access