C# create a new GUID

If you need a new GUID (not in code) and have MS Windows SDK installed, you can type this in the cmd prompt: uuidgen which will give you something like this: C:\>uuidgen ff9ddb07-bf8e-4f90-9475-8715c061231c If you need to do this at runtime in .Net, see System.Guid. System.Guid guid=System.Guid.NewGuid(); Console.WriteLine(guid.ToString);

C# Timers

There are three kinds of timers in .Net but it’s not always obvious when to use which one.  Here’s some sample code of each, and then later on a table from the MSDN website that summarizes the differences. // Runs on the UI thread // Will not raise events if UI is unable to process …

C# Suspend and Wakeup

If you need to suspend a device running on battery power programmatically and wake it back up SO THAT THE MONITOR TURNS ON you need to use the basic Suspend if the device AND the SetThreadExecutionState function. If you don’t, the device will assume there is no user activity and since no thread has signalled …

C# Using List.Find

Ever wonder how you use a Predicate Delegate to make the Find function work? Well I was wondering as well, so I found the following useful snippet on MSDN: http://msdn2.microsoft.com/en-us/library/x0b5b5bc.aspx

C# Environment variables

If you ever need to set environment variables in .Net 2.0+, you can use these: System.Environment.SetEnvironmentVariable(“MACHINE_VAR”, “Somevalue”, EnvironmentVariableTarget.Machine); System.Environment.SetEnvironmentVariable(“USER_VAR”, “Somevalue”, EnvironmentVariableTarget.User); System.Environment.SetEnvironmentVariable(“PROCESS_VAR”, “Somevalue”, EnvironmentVariableTarget.Process); string env_val = System.Environment.GetEnvironmentVariable( “PROCESS_VAR”, EnvironmentVariableTarget.Process); These however do have their limitations: If your use does not have privileges to the registry or to set environment variables these will not work. …