검색결과 리스트
글
큰 차이는 없다 null Exception 처리를 한다 안한다의 차이 뿐이다
Parse를 살펴보면 문자를 Integer로 바꿔준다.
그리고 null이 입력될경우 ArgumentNullException 처리를 해준다.
Convert.ToInt32경우는 입력값이 null일경우 0을 반환한다.
그리고 나머지는 int.Parse와 같다.
설정
트랙백
댓글
글
C#에는 재미있는 클래스들이 많이 있다.
그 중 하나가 파일 시스템을 감시하는 FileSystemWatcher 클래스가 있다.
하지만 크로스 스레드 문제로 인한 오류가 발생하는데 필자는 다음과 같이 하여 이용하고 있다.
CheckForIllegalCrossThreadCalls = false;//크로스 스레드 자체를 무시.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = txtPath.Text;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Filter = "*.*";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnChanged);
여기에서 OnChanged는 메소드로 각 해당하는 상태가 일어났을 시 그 메소드를 실행한다.
watcher.EnableRaisingEvents = true;
설정
트랙백
댓글
글
WNet을 이용해야한다.
result 변수 값이 0 이면 접근 허용
공유 폴더 경로 문제는 1203 오류 코드
사용자/암호가 일치 하지 않다면 1326 오류 코드가 발생한다.
명시적으로 로컬 드라이브를 지정하고 싶다면 NETRESOURCE 구조체의 lpLocalName 필드에
드라이브 값을 설정이 가능하다.
이미 네트워크 드라이브 사용 중이라면 오류 코드 85
사용 가능한 로컬 드라이브 (Z, Y, X, W, 등의 순서) 이름의 선택을 시스템에게 맞기고 싶다면 flags 값에 0x80 을 주면 시스템이 적절한 로컬 드라이브 이름을 선택해 줄 것이다.
capacity 값은 공유 폴더의 경로를 담을 수 있도록 충분히 주어야 하지만
그렇지 않을 경우 오류 코드 234를 반환할 것이다.
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NETRESOURCE
{
public uint dwScope;
public uint dwType;
public uint dwDisplayType;
public uint dwUsage;
public string lpLocalName;
public string lpRemoteName;
public string lpComment;
public string lpProvider;
}
[DllImport("mpr.dll", CharSet = CharSet.Auto)]
public static extern int WNetUseConnection(
IntPtr hwndOwner,
[MarshalAs(UnmanagedType.Struct)] ref NETRESOURCE lpNetResource,
string lpPassword,
string lpUserID,
uint dwFlags,
StringBuilder lpAccessName,
ref int lpBufferSize,
out uint lpResult);
public void setRemoteConnect(string strRemoteConnectString, string strRemoteUserID, string strRemotePWD)
{
int capacity = 64;
uint resultFlags = 0;
uint flags = 0;
try
{
if ((strRemoteConnectString != "" || strRemoteConnectString != string.Empty) &&
(strRemoteUserID != "" || strRemoteUserID != string.Empty) &&
(strRemotePWD != "" || strRemotePWD != string.Empty))
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(capacity);
NETRESOURCE ns = new NETRESOURCE();
ns.dwType = 1;
ns.lpLocalName = null;
ns.lpRemoteName = @strRemoteConnectString;
ns.lpProvider = null;
int result = WNetUseConnection(IntPtr.Zero, ref ns, strRemotePWD, strRemoteUserID, flags, sb, ref capacity, out resultFlags);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
RECENT COMMENT