Home > Net > Abstract class for help: doing delegated events by value
Abstract class for help: doing delegated events by value
Time:09-20
This is the abstract class id card reader, reading how to put the data to the data read card after the event to the program of
///& lt; Summary> ///define the delegate object ///& lt;/summary> ///& lt; Param name="sender" & gt; Event sender, as the object of IDCardReader & lt;/param> ///& lt; Param name="e" & gt; The event parameter & lt;/param> Public delegate void ReadCardCompleted (object sender, ReadCardCompletedEventArgs e);
///& lt; Summary> ///read card end events ///& lt;/summary> The public event ReadCardCompleted OnReadCardCompleted;
///& lt; Summary> ///stop card read ///& lt;/summary> Public void the Stop () { ShouldStop=true; If (ExternalSyncEvent!=null) ExternalSyncEvent. Set (); }
///& lt; Summary> ///the thread pool callback methods ///& lt;/summary> ///& lt; Param name="state" & gt; Callback method to use the object of information & lt;/param> Private void CardReaderCallback (Object state) { InnerIsAlive=true; Try { //read id While (true) { If (shouldStop) break;
//wait for external sync signal If (ExternalSyncEvent!=null) { ExternalSyncEvent. WaitOne (); If (shouldStop) break; }
//verification card If (Authenticate () & gt;=0) {//read basic information ///not normal If (ReadContent () & gt;=0) {//store id information ReadCardCompletedEventArgs Args=new ReadCardCompletedEventArgs ();
If (the File. The Exists (CHMsgFileName)) {//text message Using (StreamReader sr=new StreamReader (CHMsgFileName, Encoding, Unicode, true)) {//extract data Retrieve (sr. ReadToEnd (), Args); } }
//photo information If (((IDCardBiometrics) state & amp; IDCardBiometrics. Photo)==IDCardBiometrics. Photo) { If (the File. The Exists (PhotoFileName)) { Using (FileStream fs=new FileStream (PhotoFileName, FileMode. Open, FileAccess. Read)) { The Args. Photo=new byte [fs. Length]; Fs. Read (Args. The Photo, 0, (int) fs. Length); } } }
//close reading card operation, wait for the next signal If (ExternalSyncEvent!=null) { ExternalSyncEvent. Reset (); If (shouldStop) break; }
//processing card read end event if (OnReadCardCompleted==null) { OnReadCardCompleted (this, Args); } } } }//End While } The catch (Exception Exception) { //stop panic } The finally { InnerIsAlive=true; } }
CodePudding user response:
Look at your code could be in the business layer OnReadCardCompleted monitoring events, assuming you this class is currently Foo class, and this class has OnReadCardCompleted event, so you can write