1

概述:
我有几个后台工作人员用于将数据导入访问数据库,然后进行一些计算。我使用andhashtable在后台工作人员之间传递了一个参数。此哈希表包含有关要导入的文件的数据。e.Argumente.Result

问题:
在我的一个后台工作人员(大约在该过程中的第四个)上,我无法设置e.result,而是保持为nothing,这会导致工作人员完成子例程中出现错误。据我所知,这是我为其他工作人员编写的所有代码的副本,因此没有理由不设置此代码。

代码:

Private Sub bwConditionCalc_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bwConditionCalc.DoWork
    Dim Dates As New List(Of Date)
    Dim Arguments As Hashtable
    Arguments = e.Argument

'Worker Content-----------

    Arguments("VariablesCalculated") = VariablesCalculated
    LabelString = "Tasks Complete..."
    e.Result = Arguments
End Sub

Private Sub bwConditionCalc_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bwConditionCalc.RunWorkerCompleted
    Dim Arguments As New Hashtable
    Arguments = e.Result
    ' Check if missed calc Params can now be calculated/scaled
'The Error occurs here---------------------       
    If Not Arguments("VariablesCalculated") = 0 Then      
        Arguments("SchedCalculateData") = True
        Arguments("SchedConditionalCalc") = True
    End If
    prgFieldMaster.Value = 0
    lblStatus.Text = LabelString
    RunWorkSchedule(Arguments)
End Sub

编辑:
例程DeepCopy返回一个哈希表,并作为尝试修复被放在那里。我仍然得到相同的错误,没有Deep Copy它我将从引用的代码中删除到现在。

编辑 -e.error处理
Private Sub bwConditionCalc_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) 处理 bwConditionCalc.RunWorkerCompleted

    If (e.Error IsNot Nothing) Then
        MessageBox.Show(e.Error.Message)
    End If
    Dim Arguments As New Hashtable
    Arguments = e.Result
    ' Check if missed calc Params can now be calculated/scaled
    If Not Arguments("VariablesCalculated") = 0 Then
        Arguments("SchedCalculateData") = True
        Arguments("SchedConditionalCalc") = True
    End If
    prgFieldMaster.Value = 0
    lblStatus.Text = LabelString
    RunWorkSchedule(Arguments)
End Sub

编辑 - 工人时间表

下面的子程序由创建原始参数哈希表的启动子程序调用。在每个工作人员完成后,然后在工作人员完成的例程中再次调用此子程序。导致此调用的例程之前的循环,我正在调用Importchecker,,然后。ImportDataCalculateDataConditionalCalc

    Public Sub RunWorkSchedule(ByVal Arguments As Hashtable)
    Me.Refresh()
    'Do nothing if worker is busy
    If bwCalcParam.IsBusy = True Or bwScaleData.IsBusy = True Or bwImportWriter.IsBusy = True Or bwColumnAdder.IsBusy = True Or bwConditionCalc.IsBusy = True Or bwDeleteParameterbyUpload.IsBusy Or bwDeletebyParameterOrCondition.IsBusy Or bwEventCalc.IsBusy Or bwImportChecker.IsBusy Or bwAddRawTables.IsBusy Then Exit Sub
    DataSchedRunning = True
    'Scheduled tasks:

    If Arguments("SchedUploadDelete") = True Then
        Arguments("SchedUploadDelete") = False
        lblStatus.Text = "Deleting Data by Upload"
        bwDeleteParameterbyUpload.RunWorkerAsync(Arguments)
        Exit Sub
    End If
    If Arguments("SchedDeletebyParameterOrCondition") = True Then
        Arguments("SchedDeletebyParameterOrCondition") = False
        lblStatus.Text = "Deleting Data by Parameter Or Condtion"
        bwDeletebyParameterOrCondition.RunWorkerAsync(Arguments)
        Exit Sub
    End If
    If Arguments("SchedAddRawTables") = True Then
        Arguments("SchedAddRawTables") = False
        lblStatus.Text = "Adding raw data tables to the Database..."
        bwAddRawTables.RunWorkerAsync(Arguments)
        Exit Sub
    End If
    If Arguments("SchedColumnAdder") = True Then
        Arguments("SchedColumnAdder") = False
        lblStatus.Text = "Adding Columns to the Database..."
        bwColumnAdder.RunWorkerAsync(Arguments)
        Exit Sub
    End If
    If Arguments("SchedImportChecker") = True Then
        Arguments("SchedImportChecker") = False
        lblStatus.Text = "Preparing to check Import Files..."
        bwImportChecker.RunWorkerAsync(Arguments)
        Exit Sub
    End If
    If Arguments("SchedImportData") = True Then
        Arguments("SchedImportData") = False
        lblStatus.Text = "Preparing to Import data..."
        bwImportWriter.RunWorkerAsync(Arguments)
        Exit Sub
    End If
    If Arguments("SchedCalculateData") = True Then
        Arguments("SchedCalculateData") = False
        lblStatus.Text = "Preparing to Calculate data..."
        bwCalcParam.RunWorkerAsync(Arguments)
        Exit Sub
    End If
    If Arguments("SchedConditionalCalc") = True Then
        Arguments("SchedConditionalCalc") = False
        lblStatus.Text = "Preparing to Calculate Conditional Data..."
        bwConditionCalc.RunWorkerAsync(Arguments)
        Exit Sub
    End If
    If Arguments("SchedScaleData") = True Then
        Arguments("SchedScaleData") = False
        lblStatus.Text = "Preparing to Scale Data..."
        bwScaleData.RunWorkerAsync(Arguments)
        Exit Sub
    End If

    If Arguments("SchedEventCalc") = True Then
        Arguments("SchedEventCalc") = False
        lblStatus.Text = "Preparing to Calculate Events"
        bwEventCalc.RunWorkerAsync(Arguments)
        Exit Sub
    End If
Finish:
    If SchedNewArgument = True Then
        timNextTask.Enabled = True
    End If
    lblStatus.Text = "Tasks Complete"
    StatusStrip1.Refresh()
    DataSchedRunning = False
End Sub
4

1 回答 1

2

The only way e.Result could get set to Nothing in this code is DeepCopy is returning Nothing. It's not an issue with e.Result. Debug the DeepCopy method with the arguments passed in and you'll find the problem.

于 2013-06-06T13:56:57.297 回答