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

Foo Foo=new Foo ();
Foo OnReadCardCompleted +=Foo_OnReadCardCompleted;
//do something

The Foo_OnReadCardCompleted here is need your own implementation method

CodePudding user response:

reference 1st floor lindexi_gd response:
look at your code could be in the business layer OnReadCardCompleted monitoring events, assuming you this class is currently Foo class, and the class there are OnReadCardCompleted event, so you can write

Foo Foo=new Foo ();
Foo OnReadCardCompleted +=Foo_OnReadCardCompleted;
//do something

The Foo_OnReadCardCompleted here is need the method to realize your own



This
If (OnReadCardCompleted==null)
{
OnReadCardCompleted (this, Args);
}

How the data in the application layer on the Args in it

CodePudding user response:

There is Foo_OnReadCardCompleted if button click event is how to write

CodePudding user response:

refer to the second floor glide response:
Quote: refer to 1st floor lindexi_gd 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

Foo Foo=new Foo ();
Foo OnReadCardCompleted +=Foo_OnReadCardCompleted;
//do something

The Foo_OnReadCardCompleted here is need the method to realize your own



This
If (OnReadCardCompleted==null)
{
OnReadCardCompleted (this, Args);
}

How the data in the application layer on the Args inside


In Foo_OnReadCardCompleted method parameters can be got, another Foo_OnReadCardCompleted if as a button click event, I suggest you to create an event, such as the following code

Private void Button_OnClick (object sender, object args)
{
//in this event can call Foo_OnReadCardCompleted method, but call the parameters of the need according to your business incoming
}

CodePudding user response:

reference 4 floor lindexi_gd response:
Quote: refer to the second floor glide response:

Quote: refer to 1st floor lindexi_gd 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

Foo Foo=new Foo ();
Foo OnReadCardCompleted +=Foo_OnReadCardCompleted;
//do something

The Foo_OnReadCardCompleted here is need the method to realize your own



This
If (OnReadCardCompleted==null)
{
OnReadCardCompleted (this, Args);
}

How the data in the application layer on the Args inside


In Foo_OnReadCardCompleted method parameters can be got, another Foo_OnReadCardCompleted if as a button click event, I suggest you to create an event, such as the following code

nullnullnullnullnull
  •  Tags:  
  • C#
  • Related