EVENT HANDLING AND MULTITHREADING IN C# ASSIGNMENT NO: ONE SUBMITTED TO: SIR: REMEEZ IQBAL SUBMIITED BY: IQRA MUBEEN (16451556-046) SECTION: BSIT A SUBJECT: VISUAL PROGRAMMINGEvent Handling in C#:An event handler, in C#, is a method that contains is a code that is execute for a specific event that is occur in application. Event handlers are used in graphical user interface (GUI) applications to handle events as like button clicks and menu selections, raised from controls for user interface. A single event handler should be used to process events for many controls. An event could be associated with multiple event handlers, which would be invoked synchronously when the events occurs. Event handlers could be used to handle events that give signal an object’s state changes to the object’s clients.The C# event model is based on a “publish-subscribe” pattern in which a class (publisher) triggers an event, while another class (subscriber) receives that event.
An event handle has a specific code for event.For example, an event handler can be used to handle an event that occurs during the click on button it shows.In C#, an event is connected to its handler by an event delegate. To raise an event and respond to the event, the two necessary elements are the delegate that links the event to its handler method and the class that holds event data. By adding the delegate instance to the event object using the addition assignment operator (‘+=’), the event handler is called on occurrence of its associated event.
The signature of an event handler delegate includes two parameters that represent of object instance raised the event and the object holding event data. The signature of an event handler method could be match with that of the delegate for that event and for return type like void. The .NET framework provided a built-in event handler that could be used in cases where the delegates used differ only for type name and hence can reduce code that needs of maintained.
Multithreading in C#: Multithreading could be used for perform multiple tasks. Each task can have multiple threads. In a multithreaded application, the user could work more in a short period of time than a single thread application. Use of Multithreading:The main purpose of multithreading is to provide concurrent execution of parallel parts of a program for maximum adopt the CPU time. A multithreaded program has many parts that could be run concurrently. That should be called thread.