C++/Win32: How to wait for a pending delete to complete

前端 未结 13 1076
不思量自难忘°
不思量自难忘° 2020-11-30 03:20

Solved:

  • Workable solution: sbi\'s answer
  • Explanation for what really happens: Hans\'s answer
  • Explanation for why OpenFile do
13条回答
  •  温柔的废话
    2020-11-30 03:55

    I think this is just by poor design in the file system. I have seen the same problem when I worked with communication ports, opening/closing them.

    Unfortunately I think the simplest solution would be to just retry to create the file a number of times if you get an INVALID_HANDLE_VALUE. GetLastError() might also give you a better way of detecting this particular INVALID_HANDLE_VALUE.

    I would have preferred overlapped I/O, but their CloseHandle() and DeleteFile() don't handle overlapped operations :(

提交回复
热议问题