'ByRef'参数'<parametername>'不能在lambda表达式中使用

Clé*_*ent 3 vb.net lambda pass-by-reference byref

我正在使用SharpZipLib来压缩文件.该库包含在一个插件接口中,位于一个单独的DLL中.我通过插件dll一个ByRef参数来跟踪压缩进度.

SharpZipLib在压缩时会定期调用启动压缩时传递的委托子.我无法弄清楚在ByRef调用委托时如何更新参数.如果我尝试ByRef在lamba表达式的主体中分配变量,我会收到'ByRef' parameter '<parametername>' cannot be used in a lambda expression错误.

这是我的代码:

Using InputFile As New IO.FileStream(SourceFile, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
    Using OutputFile As New IO.FileStream(DestFile, IO.FileMode.Create)
        Using GZipStream As New GZipOutputStream(OutputFile)
            Dim Buffer(524228) As Byte
            Dim Handler As New ProgressHandler(Sub(Sender As Object, EventArgs As ProgressEventArgs) Progress += EventArgs.Processed)
            StreamUtils.Copy(InputFile, GZipStream, Buffer, Handler, New TimeSpan(10000000), Nothing, "")
        End Using
    End Using
End Using 
Run Code Online (Sandbox Code Playgroud)

谢谢!

小智 12

我知道这个问题已经有4年了,但我只是面临同样的问题,我想出来了,所以我想与你分享解决方案.

根据Microsoft在MSDN页面上的回答:

您必须将ByRef参数分配给局部变量,并使用lambda表达式中的局部变量.

希望答案可以帮助任何人.