Posts By Category

Posts By Date

Resources:

C# Books
ASP.NET Books DotNet4All








If you like to support this site, feel free to make a donation to support improvements.

Thank you!

Monetize Your Blog

Removing Items From a List Control (Visual C#)

I was writing a Windows Application and I had a very simple need: Remove all Selected items from a ListBox control. If you have tried to simple use code like the one below:

Continued...

A way to achieve secondary for DataTable in C#

I recently stumbled across the following C# code that allows sorting and filtering rows in a DataTable using DataTable.Select method:

http://authors.aspalliance.com/olson/methods/FilterSortData.aspx

However, what I needed was to sort on a primary column, then if DataRows had the same value for the primary column, perform a secondary sort based on another secondary column.

Continued...

Use Intermittent Sleeping (small increments) instead of one long Thread.Sleep for a quicker, more responsive multi-threaded application

We all had to use Thread.Sleep at one point or another to wait on an event to happen, or to satisfy a configuration setting during cyclic calculations or a processing. But is your worker thread sleeping too much? Does it feel sometimes that your code sleeps in the wrong time

Continued...

Using StreamReader & StreamWriter to insert a text at a given line number

System.IO.StreamWriter allows you to write text to a file easily if you are creating the file and know the order of the lines. However, what if you are trying to edit a file? For example, you need to insert a text at a specified line number in an existing text file. Say you have a text file that contains: Continued...


How to close another process's main window from a C# App without invoking Native Win32 code

Back in the good (or bad :) ) days of Win32 programming, there was a nice little function named FindWindow. It enabled you to find any window belonging to any process on your system

These days are gone with C# .NET, well... not quite!

If you have been looking for an alternative to FindWindow, Read along. There are two alternatives, the first involves invoking FindWindow directly from the Native Win32 DLL API, but that takes us back to the old days.

Continued...

System.Windows.Forms.Timer does not work for Console Applications because you need an event loop, so you need to use System.Threading to implement your own timer with an event loop, here is how...

In Console Applications, you don't have an event message loop like in a Windows Application project, hence, so you can't use the System.Windows.Forms.Timer object since it depends on Windows Message loop to fire its tick events.

Continued...

You can spawn the regedit.exe command utility to simply mimic it's behavior in your C# application, here is how...

One of my clients needed to run a script on a user machine every time the user logged in. The script would import some registry keys and settings that customize certain parts in Windows for their client.

My task was to write the script. Well, my first thought was to write a text parser for their .reg file, then using the .NET Registry classes to import all the keys into the registry one by one.

Continued...

How to parse a webpage in C#? Simple text parsing in C# using GetStringInBetween, GetStringBetween

One common requirement especially when doing screen scrapping is to find strings contained between html tags, or other strings. Regular Expressions provide a powerful way to do so, but are initially intimidating for a beginner programmer. Here is an alternative solution to finding a string between two other strings that uses simple string manipulation in C#, without Regular Expressions:

Usage:

Continued...

How to parse a webpage in C#? Text Parsing in C#

We all know how to remove/replace a string in C#, for example:

string myString = "Yousef (programmer) likes to write in C#";

To remove "(programmer)", we can write:

myString = myString.Replace("(programmer)", "");

Continued...

utilizing GetProcesses in .NET to log start and end times for currenlty running processes on yoru machine

Here is a quick C# script to log the start and end times of running processes on your machine.

The idea is query the currently running processes every x number of seconds utilizing the Process.GetProcesses function in .NET, while maintaining a book for currently running processes each cycle, then if a new process appears (or disappears), you log the result as start and end respectively.

Here is how to get currently running processes on your machine using C#:

Continued...

Use .NET Timers to setup a Clock user control on a Windows Form in C#

Making your own Clock control to display on your Windows Form to display and update the current time up to the second is an easy deal using C# Timers.

Creating The Clock User Control Step By Step

Here is one way to do it:

Continued...

Using a volatile variable to control GUI from a background thread

I was writing this application for a client of mine, and I needed to dsiplay a "Please Wait..." message while disabling access to the the rest of the application controls during a lengthy background process, but at the same time, wanted to show that the application is alive and well.... not frozen, maybe even put a cancel or a stop button to terminate the lengthy process.

Continued...

Copyright © 2007 Yousef Mannaa. All material on this site is copyrighted.
Do not publish or reproduce any of this material without written permission from the Author