A delegate declaration defines a reference type that can be used to encapsulate a method with a specific signature. A delegate instance encapsulates a static or an instance method. Delegates are roughly similar to function pointers in C++; however, delegates are type-safe and secure.

This example demonstrates how to generate log file with Delegate and Event technique.

A delegate declaration defines a reference type that can be used to encapsulate a method with a specific signature. A delegate instance encapsulates a static or an instance method. Delegates are roughly similar to function pointers in C++; however, delegates are type-safe and secure.

Event represents the state of an event, such as the element in which the event occurred, the state of the keyboard keys, the location of the mouse, and the state of the mouse buttons.

First, you will need to import the System.IO namespace.

The System.IO namespace contains the StreamWriter and File Classes.

The System.IO namespace contains types that allow reading and writing to files and data streams, and types that provide basic file and directory support.
We use the button1_Click event to do the work.
Click the button Generate Log File ,System will generate a log file in folder log which locates in root directory. The code as follows.

Add two custom class Client and UserInputMoniter in the project. The code as follows.

The front end DelegateEventVB.aspx page looks something like this:

The flow for the code behind page is as follows.

Download Source Files