Category Archives: programs

Let a thread call a form’s methods in C#

When the user clicks the Start Thread button, this program runs a counter on a separate thread. Every second the counter updates the form’s Value variable. It then displays the thread’s number and the new Value in the ListBox at … Continue reading

Posted in algorithms, programs, system, threading | Tagged , , , , , , , , , , , , , , , , | Leave a comment

Run threads with different priorities in C#

This example runs several different threads at different priorities. Each of the threads executes the following Counter class’s Run method. class Counter { // This counter’s number. public string Name; // Initializing constructor. public Counter(string name) { Name = name; … Continue reading

Posted in algorithms, programs, system, threading | Tagged , , , , , , , , , , , , , , , , , , , , | Leave a comment

Get the program’s memory usage in C#

This example uses the following code to display information about its memory usage. // Display information about the current process’s memory usage. private void Form1_Load(object sender, EventArgs e) { Process proc = Process.GetCurrentProcess(); AddItem(lvMemory, “Min Working Set”, ((double)proc.MinWorkingSet).ToFileSize()); AddItem(lvMemory, “Max … Continue reading

Posted in memory, programs | Tagged , , , , , , , , | Leave a comment

Display an end user license agreement (EULA) in C#

Many program display an end-user license agreement (EULA) when they are installed or the first time they are run. This example uses a form called EulaForm to display a RichText format EULA file. The form returns DialogResult.OK if the user … Continue reading

Posted in forms, programs, registry | Tagged , , , , , , , , , | 3 Comments

Register a program for a particular system in C#

This example demonstrates a fairly simple technique that you can use to register a program for a particular system. A determined hacker could circumvent it, but for most programs it won’t be worth the effort. The idea is simple. When … Continue reading

Posted in cryptography, programs, system, tools | Tagged , , , , , , , , , , , , | 13 Comments

Display a simple password dialog before a program starts in C#

You might think that a program could start with a password form and then display its main form if the user enters a valid password. Unfortunately when the initial password form closes, it ends the whole application. A better approach … Continue reading

Posted in dialogs, forms, programs | Tagged , , , , , , , , , , | 2 Comments

Use a BackgroundWorker in C#

This example shows how to use a BackgroundWorker component to easily perform a task in the background while the program continues running. The example Use multiple threads to draw a graph in C# lets you perform an action in the … Continue reading

Posted in controls, programs, threading | Tagged , , , , , , , , , , | 8 Comments

Use multiple threads to draw a graph in C#

This example shows how you can use multiple threads to let a program draw a graph and perform other tasks at the same time. A thread is a path of execution through a single process. Multi-threading allows an application to … Continue reading

Posted in graphics, programs, threading | Tagged , , , , , , , , , , , | 2 Comments

Make a program display its own binary code in three ways in C#

I recently wanted to put a chunk of binary code in a book to show what code really looks like to the computer, so I wrote this program. This isn’t a spectacularly useful program, but it does demonstrate a few … Continue reading

Posted in LINQ, programs, strings | Tagged , , , , , , , , , , , | Leave a comment

Start another program and wait until it finishes in C#

The example Open a file with the system’s default application in C# shows how to open a file with the program associated with that type of file. The file opens and the program that started it continues without waiting. Sometimes, … Continue reading

Posted in files, programs, system | Tagged , , , , , , , , , , , , , , , , , , , | 1 Comment