일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 셋업
- 예제
- 시리얼 통신
- dll
- 기초
- 입문
- Visual Basic
- Delphi
- Firebird
- 인스톨
- vb
- 문자열
- Visual Studio 2005
- 델파이
- 데이터베이스
- MySQL
- winsock
- 설치
- 파이어버드
- VB.NET
- WIN32 SDK
- xml
- 초보
- MFC
- c#
- SQL
- 파라미터
- 소니
- PostgreSQL
- SDK
- Today
- Total
프로그래밍 노트
[델파이]네트워크 경유한 파일 유무 체크 스레드 본문
파일 유무 체크를 하는데 있어서
네트워크 경유로 파일을 체크할 경우에는
체크하려는 네트워크가 검색이 안 될 경우에는
프로그램이 먹통이 된 것처럼 잠시 멈쳐 버린다 그런 것을 해결하기 위해서
스레드로 이 처리를 하면 지정한 시간만 기다리고 응답이 없으면
다음 처리로 넘어가게 할 수 있다.
네트워크가 아닌 경우에는 FileExists는 폴더나 파일이 없으면
바로 다음 행으로 넘어간다.
// 네트워크 파일 유뮤 체크 스레드
TCheckFileThread = class(TThread)
private
FFileName : String;
FResult : Integer;
protected
procedure Execute;override;
published
property FileName : String read FFilename write FFilename;
property Result : Integer read FResult write FResult;
end;
// 스레드 본체 : 파일 유무 체크
procedure TCheckFileThread.Execute;
begin
Result := -1;
// 파일 유무 체크
if FileExists(FileName) = True then
// 파일 유
Result := 0
else
// 파일 무
Result := 1;
Terminate;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
CheckFile : TCheckFileThread;
tick : Cardinal;
begin
// 파일 유무 체크 스레드 기동
CheckFile := TCheckFileThread.Create(True);
CheckFile.Result := -2;
CheckFile.FreeOnTerminate := False;
// wwwi가 검색하려는 컴퓨터명(ip어드레스를 입력해도 됨)
CheckFile.FileName := '\\wwwi\haha.txt';
CheckFile.Resume;
tick := GetTickCount;
// 지정한 시간 만큼 대기하고 응답이 없으면 다음으로 넘어가기
while (CheckFile.Terminated = False) and (GetTickCount - tick < 1000) do
begin
Application.ProcessMessages;
end;
case CheckFile.Result of
-1:// Timeout
begin
// 타임아웃으로 끝났을 경우 스레드 종료
TerminateThread(CheckFile.Handle, 0);
Button1.Caption := 'Timeout';
end;
0:// Ok
begin
Button1.Caption := 'Ok';
end;
1:// no file
begin
Button1.Caption := 'no file';
end;
end;
CheckFile.Free;
end;