
This is my own version of Captcha. It's easy and simple. You can improve it with your ideas or needs.using System.Diagnostics;
private void Form1_Load(object sender, EventArgs e)
{
try
{
string moduleName = Process.GetCurrentProcess().MainModule.ModuleName;
string processName = Path.GetFileNameWithoutExtension(moduleName);
Process[] aryProcess = Process.GetProcessesByName(processName);
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. People can run FindMP3.exe and FindMP3_1.exe at the same time. You can fix this by checking the filename at program startup.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");
}
.......After spending so many hours on this issue, I finally figure out what the problem is.
IPAddress serverIP = IPAddress.Parse("xx.xx.xx.xx");
IPEndPoint serverEP = new IPEndPoint(serverIP, 12345);
UdpClient client = new UdpClient();
//start listening
client.BeginReceive(new AsyncCallback(ReceiveCallback), serverEP); //here causes the problem
//send message to server and wait for response
client.Send(Encoding.UTF8.GetBytes("Hello"), "Hello".Length, serverEP);
.....