CreateFile() hangs on VMWare with a disk disconnected.

Matt McDonough 1 Reputation point
2022-02-23T17:43:02.937+00:00

I am calling CreateFile to open a file for reading and writing on an external Windows volume running over VMWare. However, if the disk is disconnected for any reason (after having been previously connected), CreateFile will hang indefinitely. How can I terminate the CreateFile attempt safely?

I've tried starting a thread to do the CreateFile and then using CancelSynchronousIO, but this call also seems to block indefinitely. As far as I can tell, the only way to abort the CreateFile attempt is with TerminateThread, which I know is a messy option that is never recommended. Is TerminateThread safe to do in this instance?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,580 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,683 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.