Skip to main content

Posts

Showing posts from August, 2019

Events in .NET

Events A class defines an event member to notify other objects For example, when a Button object is clicked, a Form object receives a notification and performs some action. The CLR’s event model is based on delegates Event member An event member declaration provides the class with three capabilities Objects can register for the event Objects can unregister the event The type that defines the event maintain the set of registered objects and notifies these objects when the event is raised. public event AlarmMessageEventhandler AlarmMessage when viewed in ILDASM, notice that compiler translates the above line to following three constructs private AlarmMessageEventhandler, add_AlarmMessage, remove_AlarmMessage. BurglarSystemManager.cs namespace Event_Demo {     /// <summary>     /// I have declared a class named BurglarSystemManager     /// </summary>     class BurglarSystemManager     {     ...

Real time data to web application using Microsoft Signal R and Razor Pages

Today we are going to learn how to create razor pages and how to send run time value to the razor page using Signal R Create a new .NET core web application Add Signal R library by,  Add Client-Side Library dialog in the project, for Provider select "unpkg" and select the latest version from the drop down For Library, enter @aspnet/signalr@1, Add a new folder to the project named as Hubs The chat hub class inherits from HUb class that manages connections and messaging The send message is called to send the message to all the clients. MyHub.cs file contains the following code using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; //using System.Threading.Tasks; namespace SignalRSample.Hubs {     public class MyHub : Hub     {         public async Task SendMessage(string user, string message)         {       ...

Delegates in .NET

What is a delegate? Microsoft framework exposes callback functionality via delegates. Call back functions are used in various application like Microsoft Windows software, OPC subscriptions in Industrial Automation software's, for providing real time data for web applications, menus, file system changes, exception handling etc.  Delegates can call multiple methods in order wise.  A delegate object is a wrapper around a method and an object to operate on. All Delegates types are derived from System.Multicastdelegate. Delegate supports the calling of both static and instance methods and callback method is type safe. How to use it? class TempretureSensor {         // Subscribers to the tempreture sensor instance         public List<int> subscribers = new List<int>();         //Define a sensor data type         public delegate void TemperatureFeedback(int unitId, double value, stri...

SQL Lite CRUD operation using Visual Studio Web Application

Problem: How do I perform CRUD operation in web? Solution: I will explain in detail steps how to write a simple web application that is capable of crud operation in SQL server.  From Visual Studio create a MVC web application. I used Visual Studio 2017. Add entity framework core, sql server compact packages from NuGet browser if you want Get a SQL lite database (mdf file) and add an employee table with columns, Id (int), name, address and phone number as varchar. Copy it to the data folder in the application folder Add a class named employee to the modal class with properties same as the column names in the employee table Add a controller class named employees Go to the appsettings.json file,  rename your copied database file to the same name as the database name in the connection string Go to the layout page and add the newly created employees CRUD operation index page to the web layout Build the project  Launch the website by pressing F5 Check if you a...

Hang due to modal overlap window

Problem: The problem was that the application would hang for one of the use cases that the customer was not sure of. Analysis:   The dump files of the hang pointed to the fact that the application hung while trying to close a window that is blocked by a modal dialog. On further analysis we could dig that, the application was hung while closing all the child windows from a menu option.The thread or the window that was blocked by the modal dialog was due to an exception message dialog. Solution: The solution was to not close a window that is blocked due to some reason. Hence the method that closed all the overlap was modified to check if the window is blocked from its window handle. All the blocked windows are left and other modeless windows are closed in that case.