'ByRef'参数'< parametername>'不能在lambda表达式中使用 [英] 'ByRef' parameter '<parametername>' cannot be used in a lambda expression

查看:174
本文介绍了'ByRef'参数'< parametername>'不能在lambda表达式中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SharpZipLib压缩文件。该库包装在单独的DLL中的插件接口中。我向插件dll传递了一个 ByRef 参数来跟踪压缩进度。

I'm using SharpZipLib to compress files. The library is wrapped in a plugin interface, in a separate DLL. I pass the plugin dll a ByRef parameter to keep track of the compression progress.

SharpZipLib在压缩时会启动压缩时,定期调用传递的委托子。调用委托时,我不知道如何更新 ByRef 参数。如果我尝试在lamba表达式的主体中分配 ByRef 变量,则会得到'ByRef'参数'< parametername>'不能为在lambda表达式中使用 c错误。

SharpZipLib, while compressing, will periodically call a delegate sub passed when launching the compression. I can't figure out how to update the ByRef parameter when the delegate is called. If I try to assign the ByRef variable in the body of a lamba expression, I get a 'ByRef' parameter '<parametername>' cannot be used in a lambda expression error.

这是我的代码:

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 

谢谢!

推荐答案

我知道这个问题已经4岁了,但是我正面临着同样的问题,我想通了,所以我想与您分享解决方案。

I know that question is 4 years old but i'm just facing the same problem and i figured it out so i want to share the solution with you.

根据Microsoft在 MSDN 页:

According to the Microsoft answer on the MSDN page:


您必须将 ByRef 参数分配给局部变量,而
在lambda表达式中使用局部变量。

You have to assign the ByRef parameter to a local variable, and use the local variable in the lambda expression.

希望答案能帮助任何人。

Hope the answer help anyone.

这篇关于'ByRef'参数'&lt; parametername&gt;'不能在lambda表达式中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆