Home   Notes   Contact Me

.Net Framework


Signaling and Passing Data to the GUI Thread

Non GUI Thread

// This passes an int and a string to the GUI thread Action action = new Action(DoGuiUpdate); this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, action, 5, "a string");

Handler that will be called on GUI thread

private void DoGuiUpdate(int number, string Str) { // Do something }

Executing a Process from Code

Process process = new Process(); process.StartInfo.Arguments = "/c netstat -noa"; process.StartInfo.CreateNoWindow = true; process.StartInfo.FileName = "cmd.exe"; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.Start(); string strOutput = process.StandardOutput.ReadToEnd(); process.WaitForExit();

URI Encoding Text

String str = System.Uri.EscapeDataString("""); // str is: "%3Cthis%20%26%20is%20line1%0D%0Aline2%20it%20%25%20%3E"

using used to Delete an Object automatically when it goes out of scope

Use the using statement

public void foo() {
    using( Object obj = new Object) {
        obj.DoSomething();
    }
    // obj gets deleted here
}

Type Conversion System.Convert


Global Exception Handler

Uncaught exceptions can be caught by this.

public static void Main()
{
    System.Windows.Forms.Application.ThreadException += System.Thread.ThreadExceptionEventHandler( OnAppException);
}

private static void OnAppException( Object sender, ST.ThreadExceptionEventArgs e)
{
}

WebClient System.Net.WebClient

MethodDescription
string DownloadString(Uri)Downloads data at link.
byte[] DownloadData(Uri)
DownloadFile(Uri, string Filename)Downloads the data to a file.
stream OpenRead(Uri)

XML System.XML

XmlDocument

MethodDescription
.Load(Stream)Loads the XmlDocument from an input stream.

XmlNode

MethodDescription
.InnerTextThe text between the 2 tags of the node.
.ChildNodesGet a collection of all the child nodes.
.SelectNodes(string)Gets a collection of the child nodes with the given name.
.SelectSingleNode(string)Selects the first node with the give name.

ArrayList System.Collections.ArrayList

MethodDescription
Add( Object);

Array System.Array

Given:
int [] arInts = new int[10];

MethodDescription
BinarySearch
CopyTo( targetArray, 0);Copy one array to the other, I don't know what the 2nd parameter is.

Queue System.Collections.Queue

MethodDescription
Contains
Dequeue
Enqueue
Peek

Queue System.Collections.Stack

MethodDescription
Pop
Push

Hashtable System.Collections.Hashtable

MethodDescription
Add( Obeject key, Object value);
ContainsKey( Object key);
Collection Keys();Returns all the keys in the table
Object operator[ Object key];C# way of accessing the data

Data Structures

Data Structures

Generics (like c++ Templates)

Note: Not before .NET 2.0

MSDN Articles

  1. An Extensive Examination of Data Structures, Part 1: An Introduction to Data Structures
  2. An Extensive Examination of Data Structures, Part 2: The Queue, Stack, and Hashtable
  3. An Extensive Examination of Data Structures, Part 3: Binary Trees and BSTs
  4. An Extensive Examination of Data Structures, Part 4: Building a Better Binary Search Tree contains information about "Skip Lists"
  5. An Extensive Examination of Data Structures, Part 5: From Trees to Graphs
  6. An Extensive Examination of Data Structures, Part 6: Efficiently Representing Sets

With C++

Making a C++ .NET Forms project by hand http://www.developer.com/net/net/article.php/1378751 "Building a .NET Windows Forms App in Visual C++ .NET"

Commonly Needed .NET libraries

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.Data.dll>

Message Box

#using <system.windows.forms.dll>
using namespace System::Windows::Forms;

namespace TestSceneGraphWrapper
{
	public __gc class Wrapper
	{
		void Test() {
			System::Windows::Forms::MessageBox::Show(
				"Message",
				"title",
				MessageBoxButtons::OKCancel,
				MessageBoxIcon::Information
			);
		}
	};
}

Dialog

To open a Form as a modal Dialog, call .ShowDialog() to open it non-modal, call .Show()