本文介绍了如何检查Shell32.Folder.CopyHere()完成的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Shell32解压缩应用程序中的某些文件.现在,我使用srcFolder.CopyHere(destFolder.Items())来实现这一目标.但是,我的下一行代码需要新创建的ZIP文件.但是由于CopyHere方法是Async,如何检查它何时完成?现在,我使用Thread.Sleep大约500毫秒,这足以让我的计算机完成创建ZIP文件的操作,但这不是imo好的代码.

I need to unzip en zip some files in my application using Shell32. Right now, I use srcFolder.CopyHere(destFolder.Items()) to achieve this. However, my next line of code requires the newly made ZIP-file. But since the CopyHere method is Async, how can I check when it in finished? Right now I use a Thread.Sleep for around 500 ms which is enough for my computer to finish creating the ZIP file, but it's not good code imo.

有什么想法吗?

如有必要,可以提供更多的信息/代码.

More info/code can be provided if necessary.

推荐答案

我找到了它,使用了类似的东西:

I found it, used something like this:

  srcFolder.CopyHere(destFolder.Items())


            While FileInUse(FILEPATH & "BudgetJaarOverzichtSMB.zip")
                Thread.Sleep(100)
            End While

    Private Function FileInUse(ByVal FilePath As String) As Boolean
        Try
            FileOpen(1, FilePath, OpenMode.Input)
            FileClose(1)
            Return False    ' File not in use
        Catch ex As Exception
            Return True     ' File in use
        End Try
    End Function

并不是很完美,但是与我的第一种方法相比,所花费的时间更少.

Not really perfect but will lose less time than with my first approach.

这篇关于如何检查Shell32.Folder.CopyHere()完成的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 02:48