FileExists 限定 TimeOut 時間 |
答題得分者是:lu
|
DaiMan
一般會員 發表:4 回覆:3 積分:1 註冊:2002-05-11 發送簡訊給我 |
|
lu
高階會員 發表:11 回覆:189 積分:195 註冊:2003-11-19 發送簡訊給我 |
|
DaiMan
一般會員 發表:4 回覆:3 積分:1 註冊:2002-05-11 發送簡訊給我 |
感謝指教,
其實在下也在 msdn 看到有人提供控制 thread 的方法,不過是用 VB寫的,小弟才疏學淺,不知如何改寫。 原文如下,在下也會嘗試前輩指教的方法試試,謝謝。 Private Class FileExistsHelper Public Shared Function FileExists( _ ByVal file As String, _ ByVal timeOut As Integer) As Boolean m_File = file m_Exists = False m_Thread = New System.Threading.Thread(AddressOf CallFileExists) m_Thread.Start() m_Thread.Join(timeOut) m_Thread.Abort() Return m_Exists End Function Private Shared Sub CallFileExists() m_Exists = My.Computer.FileSystem.FileExists(m_File) End Sub Private Shared m_Thread As System.Threading.Thread Private Shared m_File As String = String.Empty Private Shared m_Exists As Boolean = False End Class Just use it like this Dim b As Boolean = FileExistsHelper.FileExists(filePath, 2000) Note that the class itself is not safe for multi-threading though.
編輯記錄
DaiMan 重新編輯於 2008-02-28 08:41:58, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |