Posted
Filed under .NET/C#
C# 에서 Thread.Sleep 등을 이용해서 Delay를 줄 순 있지만...
프로그램이...간혹 멈춰 버리는 문제가 발생해서...

 /// 
 /// Delay 함수 MS
 /// 
 /// (단위 : MS)
 /// 
 private static DateTime Delay(int MS)
 {
    DateTime ThisMoment = DateTime.Now;
    TimeSpan duration = new TimeSpan(0, 0, 0, 0, MS);
    DateTime AfterWards = ThisMoment.Add(duration);

    while (AfterWards >= ThisMoment)
    {
        System.Windows.Forms.Application.DoEvents();
        ThisMoment = DateTime.Now;
    }

    return DateTime.Now;
 }
메소드 작성하시고 나서 .. Delay를 걸어줄 곳 찾아서 Delay(100); 식으로 입력하시면 됩니다.
단위는 밀리초로.. 1000 = 1초 입니다.
2011/08/03 12:54 2011/08/03 12:54
Posted
Filed under .NET/C#
C# 에서 Wav파일 재생하는 가장 기초적인(?) 방법입니다.
//소리재생을 위해 namespace를 추가해 줍니다.
using System.Media;

SoundPlayer wp = new SoundPlayer("../../동전소리.wav");
//wav파일이 들어 있는 경로를 설정해주세요
wp.PlaySync();
2011/05/10 02:57 2011/05/10 02:57
Posted
Filed under .NET/C#
C#으로 자신의 IP를 확인 하는 방법입니다.
using System.Net;
using System.Net.Sockets;
//네임스페이스를 추가 해 줍시다..

public string Get_MyIP()
{
	IPHostEntry host = Dns.GetHostByName(Dns.GetHostName());
	string myip = host.AddressList[0].ToString();
	return myip;
}
return 값으로는 ip를 리턴 해주고 있습니다.. 근데 현재 이 소스는 닷넷 프레임워크 2.0 이상에서는 사용을 하지 않도록 권장(?) 하고 있습니다.. 아래 코드는 GetHostEntry를 이용하여 IP 주소를 받아 내고 있습니다. 하지만 비스타 이상에서는 IPv6으로 IP주소를 출력하고 있습니다. if문을 통하여 IP주소 체계가 IPv4인 경우에만 출력하도록 해 주고 있습니다.
/// 
/// 클라이언트 IP 주소 얻어오기...
/// 
public static string Client_IP
{
	get
    {
		IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
		string ClientIP = string.Empty;
        for (int i = 0; i < host.AddressList.Length; i++)
        {
			if (host.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
            {
				ClientIP = host.AddressList[i].ToString();
            }
		}
		return ClientIP;
	}
}
외부 IP 주소 가져오기 - http://bluene.net/blog/547
2011/04/22 23:09 2011/04/22 23:09