Method 1: Once acquired, asynchronously write /// Public State (FileStream Fstream, AutoStevent Autoevent) {this.fstream = fstream; this.autoevent = autoevent;}} static void endwritecallback State stateInfo = (State) asyncResult.AsyncState; int workerThreads; int portThreads; try {ThreadPool.GetAvailableThreads (out workerThreads, out portThreads); stateInfo.fStream.EndWrite (asyncResult); Thread.Sleep (1500);} finally {stateInfo. Autoevent.set ();}} method 2: online reading, asynchronous write /// reader.GetBytes (6,0, ImageContent, 0, Convert.ToInt32 (reader.GetString (7))); AutoResetEvent manualEvent = new AutoResetEvent (false); FileStream fStream = new FileStream (strDirectory fileName, FileMode.Create, FileAccess. ReadWrite, FileShare.None, 4096, true); IAsyncResult asyncResult = fStream.BeginWrite (ImageContent, 0, ImageContent.Length, new AsyncCallback (EndWriteCallback), new State (fStream, manualEvent)); manualEvent.WaitOne (5000, false); FSTREAM.CLOSE ();} reader.close (); // Close connection IF (cnn.state == system.data.connectionState.open) {cnn.close ();} strerr = "; // Release Resource CNN .Dispose (); cmd.Dispose (); GC.Collect (); return true;} class State {public FileStream fStream; public AutoResetEvent autoEvent; public State (FileStream fStream, AutoResetEvent autoEvent) {this.fStream = fStream; this. Autoevent = autoevent;}} static void endwritecallback (iasyncResult asyncRESULT) { State stateInfo = (State) asyncResult.AsyncState; int workerThreads; int portThreads; try {ThreadPool.GetAvailableThreads (out workerThreads, out portThreads); stateInfo.fStream.EndWrite (asyncResult); Thread.Sleep (1500);} finally {stateInfo. AUTOEVENT.SET ();}} Two ways to compare: mode 1: Suitable for the database load, binary data size is known; mode 2: Suitable for unknown on the database load and binary data size; : The asynchronous mechanism of two ways is the same, without any difference; the asynchronous mechanism is the advantage of fully utilizing the operating system Note: In the context of the performance of performance, the asynchronous mechanism must be used to use synchronization mechanism To improve authenticity