Open explorer window and wait for it to close

前端 未结 2 1730
半阙折子戏
半阙折子戏 2020-12-21 08:21

I have a program that is opening an explorer window to a certain folder but i want to perform an action right after the explorer window is closed, but if I use the following

2条回答
  •  半阙折子戏
    2020-12-21 08:47

    The problem is explained pretty well at The Old New Thing:

    The reason that WaitForSingleObject returns immediately is that Explorer is a single-instance program (well, limited-instance). When you open an Explorer window, the request is handed off to a running copy of Explorer, and the copy of Explorer you launched exits. That's why your WaitForSingleObject returns immediately.

    He offers a couple solutions you could probably use (with some heavy use of PInvoke), like using something like this.

    In the end it might just be easier for you to use some other type of file browser maybe from a C# library somewhere that you have more control over, rather than explorer.

提交回复
热议问题