How to register a global hotkey for your application in C#

How to register a global hotkey for your application in C#

Register a hotkey for your application that can be triggered even if your form is minimized and does not have focus. More »

How to download a file in C# (progressbar and download speed)

How to download a file in C# (progressbar and download speed)

Learn how to download files in C# while displaying the percentage and the download speed. More »

UDP hole punching implementation in C#

UDP hole punching implementation in C#

Learn how to implement UDP hole punching so you can make your clients life a lot easier by not forcing them to open ports on their end. More »

 

Lower your ping by disabling Nagle’s algorithm

By default Windows uses the Nagle’s algorithm when handling messages. That means that in order for your connection to send a message, that message needs to be at least the size of MSS (maximum segment size), which in most cases it is inefficient when dealing with small sized packets and situations that deal with real-time systems. Because these reasons disabling Nagle’s algorithm can considerably lower your latency/ping.

In order to disable Nagle’s algorithm simply following these steps:

  1. Open up the Registry Editor. Click start --> Run and type in regedit
  2. Navigate to the following key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces
  3. You will notice that there are a few interfaces with the following format: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}. Simply navigate to all of them and look for clues (usually the value of DhcpIPAddress) that will indicate which is your default interface. Alternative you can do the next steps for all interfaces that are not empty if you want to disable Nagle’s algorithm on all devices.
  4. Right click on an empty space in the right window and select New –> DWORD (32-bit) Value and set its name to TcpAckFrequency. Then double click the key in order to modify it and change its value data to 1
  5. Repeat step 4 but this time set the name of the DWORD (32-bit) Value key to TCPNoDelay. Then again make sure to modify the key and change its value data to 1
  6. Restart your Windows and you are done!
Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

Calculate file checksum

You might have noticed by now that a lot of websites list their files checksum values in their downloads section. Checksums are extremely useful when you want to verify that the file you have downloaded from another source is indeed the same file that is hosted on the official website and that it has not been altered in any way.

For this very reason I’ve put together a method that will generate the checksum of the file of your choice. Simply provide the location of the file and the algorithm you wish to compute the checksum with.

Examples:

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

Upload file to FTP

This is a simple method that will allow you to upload a file of your choice to an FTP server.

Keep in mind that you will want to do some error catching to ensure that the file exists, the server is responding and so on.

Simply call the method as follows:

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

Download file from FTP

I’ve created a simple method for you that will download a file from an FTP server and save it in the location you wish.

Keep in mind that ideally you will want to do some error catching for cases that the file does not exist or the server is down and so on.

Simply call the method as follows:

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

Custom form background color

Winforms by default don’t offer much customization as far as coloring, especially when it comes down to gradient patterns.

If you want to change the background of your form to something a bit more unique to make it look like this

Custom form background
then simply follow steps below.

First handle the form’s Paint event.

Feel free to change the colors and the gradient direction to what you would like.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone