[C# 2.0] Get and Check Daylight Saving Time (DST)

Here is the way to get the DST:

using System.Globalization;

public static DataTable GenerateDST(int startYear, int endYear)
{
DataTable dt = new DataTable();
//get the current timezone
TimeZone oTimeZone = TimeZone.CurrentTimeZone;
DaylightTime oDST;

dt.Columns.Add("Year");
dt.Columns.Add("Start Date");
dt.Columns.Add("End Date");

for (int i = startYear; i <= endYear; i++)
{
oDST = oTimeZone.GetDaylightChanges(i);
dt.Rows.Add(oDST.Start.Year, oDST.Start.ToShortDateString(), oDST.End.ToShortDateString());
}

oTimeZone = null;
oDST = null;

return dt;
}

[C#]My simple version of Captcha

This is my own version of Captcha. It's easy and simple. You can improve it with your ideas or needs.

[C#][WinForm]Prevent same process to be executed more than once at the same time: a simple approach

This is a simple and easy way to do it if your requirement is simple. Otherwise you should use Mutex.

using System.Diagnostics;

private void Form1_Load(object sender, EventArgs e)
{
try
{
string strModuleName = Process.GetCurrentProcess().MainModule.ModuleName;
string strProcessName = Path.GetFileNameWithoutExtension(strModuleName);
Process[] aryProcess = Process.GetProcessesByName(strProcessName);

if (aryProcess.Length > 1)
{
MessageBox.Show("This program is running already!");
this.Close();
}

//...
}
catch (Exception ex)
{
//...
}
}
Note: This will check the process based on the filename. It will not work if the filename is different. For example, if you make a copy of your program (let's say FindMP3.exe) and rename it to a different name like FindMP3_1.exe. That means, people can run FindMP3.exe and FindMP3_1.exe at the same time.

You can find other approaches from here.

[C#]Simple windows registry manipulation

using Microsoft.Win32;

//Attempt to open the key.
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Play\WindowPosition");

//The key doesn't exist if it returns null.
if (key == null)
{
//Create & open it.
key = Registry.CurrentUser.CreateSubKey(@"Software\Play\WindowPos");
key.SetValue("PositionX", Location.X);
key.SetValue("PositionY", Location.Y);
}
else
{
//Get value
Location.X = key.GetValue("PositionX");
Location.Y = key.GetValue("PositionY");
}

GetWords

Name: GetWords
Version: 1.3
Platform: Windows with .Net Framework 2.0 installed
Introduction:
Fetch words from the given article. It will fetch, sort, remove duplicated words. It will ignore the word that less than 3 characters like am, is, as... etc.
How to use:
1.Paste anything you want to parse on the left-hand side textbox.
2.Click the "Get Words!" button, and the result will show on the right-hand side.

Random Posts

Powered by Stuff-a-Blog