Blog Maintenance

I am moving my blog content to WordPress, so it will be under maintenance and Posts will migrated here periodically during this week, hopefully to be up and  running no longer than July 2, 2015.

See you soon.

Detecting internet connection state using javascript

A lot of people over the net asks the same question :

How to find out if the Internet connection is connected or disconnected in ASP.NET?

But ASP.NET runs on the server, so if the user’s Internet connection is disconnected,then the browser will not be able to connect to the web server to run ASP.NET code, that’s why I thought this code should be client-side, so I digGed a little in java-script and here is an example of what I found out:

I test it on Internet Explorer 7 and Mozilla and it worked well.

USB Port Insert / Remove detection (Part 2)

This post will contain only a simple console application source code about how to detected the insertion or removal of any USB device, for more details on the code please read USB Port Insert / Remove detection

USB Port Insert / Remove detection

Almost all modern peripheral devices use the USB port as an interface to connect to the PC. This post will show how to detect an insertion or removal of a device in a USB port.

I will use the Windows Management Instrumentation (WMI) which is a component of the Windows operating system that allows you to programmatically access management information in an enterprise environment.

First we should add the System.Management name space as a reference to our project

The add: using System.Management;

When a USB device is inserted a ‘Win32_USBControllerdevice’ record is added to the operating system’s metabase and when the device is removed, that record will be deleted.

So we have to add two events to the same record and these events are “__InstanceCreationEvent” for insertion and “__InstanceDeletionEvent”  for removal.

The following method “AddHandler()” adds an event handler that is fired when a USB device is inserted.

Important note: you should stop the watcher before exiting the application or else an exception is thrown

Now to add another handler for that fire when the USB device is removed all you have to do is just to set the EventClassName property of the WqlEventQuery object to “__InstanceDeletionEvent”.

Just Graduated

Just Graduated

Today I just got graduated from college, I am now a computer systems engineer.

I’m so excited that now I will have enough time to get back to work with .NET technologies

Improve image processing performance

Since I’m working on my graduation project ( Iris recognition system ) using C#, I got involved in building the image processing basic functionalities such as: image enhancement, convert to gray, convolutions, edge detectors etc… , so I have to reach every single pixel of the Bitmap image, but when dealing with .NET Framework built-in methods: getPixel() and setPixel(), it takes about 4 seconds only to convert an image to gray (this is unacceptable, because many steps of convolutions, filters should be applied before I can get the needed information) so after a while I found a new approach, fast and efficient, it’s the unsafe code which deals directly with the memory but at the same time it is under the control of the CLR, for more information visit:

Unsafe code programming in C# (Code Project)

Painless yet unsafe gray-scale conversion in C# (Code Project)


Convert image to gray scale

An image in a computer consists of three main color channels, they are RED, GREEN, and BLUE. So each pixel in an image has three values one for each channel ranging from 0 up 255. In order to get the gray-scale of an image one channel should be used instead, and each pixel then will have only one value called the Gray level. To obtain the Gray level for a pixel of an image, we should use the following formula:

Gray = 0.3 * RED + 0.6 * GREEN + 0.1 * BLUE

This method applies the previous formula on the pixels of a given image resulting the gray level of the image.