Skip to main content

Posts

Showing posts with the label Timer

Asynchronous Programming Model(APM) with .Net

Namespace: System.Threading Asynchronous programming is simply allowing some portion of code to be executed on separate threads. Many .Net Framework classes support APM with methods like BeginXXX and EndXXX . FileStream FS = new Filestream(Filename, FileMode.Open, FileAccess.Read, FileShare.Read, 1024, FileOptions.Asynchronous); IAsyncResult vResult = FS.BeginRead(buffer, 0 , Buffer.length, null, null); //Do your work int NoOfBytes = FS.EndRead(vResult); FS.Close(); This type of APM is 1. Rendezvous Wait-Until-Done model . 2. Rendezvous Polling Model : Keeping doing some other work along with checking whether the APM work is completed or not. IAsyncResult vResult = FS.BeginRead(buffer, 0 , Buffer.length, null, null); While ( ! vResult.IsCompleted ) { //Do your work } int NoOfBytes = FS.EndRead(vResult); FS.Close(); 3. Callback Model :               ...