首页 \ 问答 \ 向后台工作者传递值(Passing Values To and From Background Worker)

向后台工作者传递值(Passing Values To and From Background Worker)

我是一个自学成才的新手试验Rijndael加密算法 ,我之前已经很好地工作了,但是因为我试图让后台工作者运行加密来为用户释放表单我遇到了很多问题。

首先,我尝试将我在前面的代码中使用的byval放入后台工作器,但是我得到了一个错误,它不兼容 - 特别是ByVal Direction As CryptoAction

所以要清楚,我正在尝试这样的事情:

Private Sub bw_DoWork(ByVal sender As Object,ByVal strInputFile As String,
                                     ByVal strOutputFile As String,
                                     ByVal bytKey() As Byte,
                                     ByVal bytIV() As Byte,
                                     ByVal Direction As CryptoAction, ByVal e As DoWorkEventArgs)


    Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)

    For i = 1 To 1
        If bw.CancellationPending = True Then
            e.Cancel = True
            Exit For
        Else

            'Encryption code goes here. 
end sub 

但正如我所说,我被告知方向与CrytoAction不兼容。 在完整的completness中,那个sub是:

Private Enum CryptoAction
        'Define the enumeration for CryptoAction.
        ActionEncrypt = 1
        ActionDecrypt = 2
    End Enum

所以为了让代码工作,我完成了这个,我认为这就是为什么我的加密文件解密成一个不可读的文件,我有时会得到错误: 填充无效,无法删除 。 关闭文件流时。

所以我在我的公共类中声明了bytkey,byIV,Direction和其余部分,就像我说的那样让代码运行。 但是我可以在加密后恢复文件。 我的想法是,当我的代码引用函数时,它不是接收返回的值,而是接收一个空字符串?

这是引用生成密钥的函数的代码,只是为了清楚我的意思。

                 Select Case Direction
                        Case CryptoAction.ActionEncrypt
                            csCryptoStream = New CryptoStream(fsOutput, _
                            cspRijndael.CreateEncryptor(bytKey, bytIV), _
                            CryptoStreamMode.Write)

                    Case CryptoAction.ActionDecrypt
                        csCryptoStream = New CryptoStream(fsOutput, _
                        cspRijndael.CreateDecryptor(bytKey, bytIV), _
                        CryptoStreamMode.Write)
                End Select

所以,我的问题是,我是正确的,代码是从声明中引用空值,还是代码仍然引用函数? 并且,是否可以将ByVal CryptoStream添加到后台工作程序中?

我对我的问题的大小我最真实的道歉,我到处寻找解决方案,但找不到任何相关的东西。


I'm a self-taught novice experimenting with the Rijndael encryption algorithm, I've previously got it to work very well, but since trying to get the encryption to run on a background worker to free-up the the form for the user I've ran into numerous issues.

Firstly I tried just placing the byval's I used in my previous code into the background worker, but I got an error with it not being compatible -- Specifically the ByVal Direction As CryptoAction.

So to be clear, I was trying something like this:

Private Sub bw_DoWork(ByVal sender As Object,ByVal strInputFile As String,
                                     ByVal strOutputFile As String,
                                     ByVal bytKey() As Byte,
                                     ByVal bytIV() As Byte,
                                     ByVal Direction As CryptoAction, ByVal e As DoWorkEventArgs)


    Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)

    For i = 1 To 1
        If bw.CancellationPending = True Then
            e.Cancel = True
            Exit For
        Else

            'Encryption code goes here. 
end sub 

But as I said, I was being told the Direction As CrytoAction was not compatible. In teh intrest of completness, that sub was:

Private Enum CryptoAction
        'Define the enumeration for CryptoAction.
        ActionEncrypt = 1
        ActionDecrypt = 2
    End Enum

So in order to get the code to work I done this, and I think this is why my encrypted files decrypt into a unreadable file and I sometimes get the error: Padding is invalid and cannot be removed. when closing the file stream.

So I declared the bytkey, byIV, Direction and the rest in my Public Class, this, as I said let the code run. But I can get the file back once encrypted. My thinking is that when my code references the functions, instead of receiving the returned value, it's receiving an empty string?

Here's the code that references the functions which generate the keys, just to be clear at what I'm meaning.

                 Select Case Direction
                        Case CryptoAction.ActionEncrypt
                            csCryptoStream = New CryptoStream(fsOutput, _
                            cspRijndael.CreateEncryptor(bytKey, bytIV), _
                            CryptoStreamMode.Write)

                    Case CryptoAction.ActionDecrypt
                        csCryptoStream = New CryptoStream(fsOutput, _
                        cspRijndael.CreateDecryptor(bytKey, bytIV), _
                        CryptoStreamMode.Write)
                End Select

So, my question is, am I right that the code is referencing nulled values from the declarations, or would the code still reference the functions? And, is it possible add the ByVal CryptoStream into the background worker?

My sincerest appologise for the size of my question, I've looked everywhere for a solution but can't find anything relevant.


原文:https://stackoverflow.com/questions/27555467
更新时间:2022-12-14 22:12

最满意答案

因为您的条件是response == "Thank You! Your message has been sent."

并且您的结果是"Please Click on the Captcha", "Thank You. Your order has been sent and a copy mailed to your inbox.", "There appears to be an issue with our server, please ring 0420 903 950 or email contact@diysoakwells.com.au.".

所以你的所有结果都会分开


because your condition is response == "Thank You! Your message has been sent."

and your results are "Please Click on the Captcha", "Thank You. Your order has been sent and a copy mailed to your inbox.", "There appears to be an issue with our server, please ring 0420 903 950 or email contact@diysoakwells.com.au.".

so all of your result will do else part

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。