我的印象是,如果一個應用程序有一個打開的句柄,並且崩潰了,句柄不會被釋放,並且如果你嘗試訪問那個句柄(比如說一個文件),那麼你會得到一個錯誤。應用程序崩潰時打開句柄會發生什麼? (Windows XP以上)
但是,我已經在Windows XP以上的版本中嘗試過,並且如果我在關閉句柄之前關閉了任務管理器中的exe,句柄似乎會被釋放。以下是代碼:
Private Sub Form_Load()
Dim iFile As Integer
iFile = FreeFile
Open "myfilelock" For Output Lock Read Write As #iFile
MsgBox "About to close" 'close it here with task manager
Close #iFile
End Sub
那麼,Windows XP是否會釋放所有打開的句柄,以防這些句柄的exe崩潰?
+1。雖然在Windows 95之前有Windows的版本,但你知道這在16位Windows中並不是這樣,但我猜這是現在的古代歷史......也許http://blogs.msdn.com/oldnewthing/archive/ 2004/03/01/82103.aspx – MarkJ