Category Archives: programs

Display memory usage in C#

This program displays the computer’s total and free physical, virtual, and page file memory usage. When it starts, the following code displays the system’s memory information in the program’s ListView control. // Prepare the ListView and display values. private void … Continue reading

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

Evaluate numeric expressions that are entered by the user in C#

This example shows one way to evaluate mathematical expressions entered by the user at runtime. Enter a numeric expression involving x and y in the upper text box. Then enter values for x and y in the lower text boxes … Continue reading

Posted in algorithms, mathematics, miscellany, programs, reflection | Tagged , , , , , , , , , , , | 2 Comments

List languages that you can compile at runtime in C#

The example Run user-entered code in C# shows how to let the user enter C# code, compile at runtime, and execute the result, but how do you know what languages you can compile that way? You might guess C# and … Continue reading

Posted in algorithms, miscellany, programs, reflection | Tagged , , , , , , , , , , , , , , , , , | 1 Comment

Run user-entered code in C#

This example shows how to compile and run user-entered code at run time. The form includes the following using statements. using System.CodeDom.Compiler; using System.Reflection; The following code executes when you click the Run button. // Compile and execute the code. … Continue reading

Posted in algorithms, miscellany, programs, reflection | Tagged , , , , , , , , , , , , , , , , | 6 Comments

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 , , , , , , , , , | Leave a comment

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 , , , , , , , , , , , , | Leave a comment

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 , , , , , , , , , , | Leave a comment