2017-07-15 1 views
0

ブール型データ型の値を設定するためにParameterizedThreadStartを使用すると問題が発生します。返されるときに常にFalseと表示されます。 (Dim BoolH? As Booleanは)それはBoolH関数からのParameterizedThreadStartでのブール値の設定

には何も示さず、ここに私のFrm_ChkHash.MatchHash機能コードです

'smth 
Frm_ChkHash.Show() 
Frm_ChkHash.BringToFront() 

Dim BoolH As Boolean 
Dim thdC = New Thread(New ParameterizedThreadStart(Function() BoolH = Frm_ChkHash.MatchHash(Keyl))) 
thdC.Start() 
'smth (Wait the thread until exit) 
Debug.WriteLine("It is " & BoolH) 
'smth 

Debug.WriteLine("It is " & BoolH)ショーFalseBoolH

でのNullableとしてそれを作ってみました。ここでは

は私のコードです:

Public Function MatchHash(ByVal Keyl As String) As Boolean 

    Dim nameApp As String = dicLbl.Item(Keyl) 
    Debug.WriteLine("Hey! I am checking " & nameApp) 

    Thread.Sleep(1500) 
    InitHsh() 
    Thread.Sleep(2000) 

    Dim GetHash As String = KHash.GenerateHash(pathFile, HashCheck.HashType.SHA1) 
    'The KHash.GenerateHash returns a String. 
    Thread.Sleep(1500) 

    'Find the Actual Hash in the Dictionary through the key. 
    Dim ActualHash As String = dicHsh.Item(Keyl) 
    Debug.WriteLine("The actual hash is: " & ActualHash) 

    Dim StrCmp_Hash As Boolean = StringComparer.OrdinalIgnoreCase.Equals(ActualHash, GetHash) 
    Debug.WriteLine("The hash is " & CStr(StrCmp_Hash)) 

    If StrCmp_Hash = True Then 

     Debug.WriteLine("The hash is correct!") 
     Debug.WriteLine("It is cool: " & dicHsh.Item(Keyl)) 
     Debug.WriteLine("And I get : " & GetHash) 

     Thread.Sleep(1500) 
     Hide() 

     Return True 

    Else 

     Debug.WriteLine("I get" & GetHash & "But it is" & dicHsh.Item(Keyl)) 

     Thread.Sleep(1500) 
     Hide() 
     Return False 

    End If 

    Hide() 

End Function 

マイ出力ウィンドウは、次のように示しています

 
Hey! I am checking ThisApp  <--- This comes from MatchHash function 
The actual hash is: E2133C93F55C7DF4EA44DC0F5455F4A2EE637E8B 
The hash is True 
The hash is correct! 
It is cool: E2133C93F55C7DF4EA44DC0F5455F4A2EE637E8B 
And I get : E2133C93F55C7DF4EA44DC0F5455F4A2EE637E8B 
The thread 0x8cc has exited with code 0 (0x0). <--- IDK where this line comes form 

It is  <--- The function had returned. (After `thdC.start()`) 

すべてのヘルプは高く評価されています。

答えて

1

問題は、あなたの委任者の '='演算子が代入演算子ではなく比較演算子として機能していることです。それが何をしているか

はこれです:

Function() 
    return BoolH = Frm_ChkHash.MatchHash(Keyl) 
End If 

あなたはそれがNULL可能にする場合BoolHがnullである理由です。

BoolHに値を割り当てる場合は、Function()の代わりに 'Sub()'を使用するか、委任者に複数行のステートメントを作成します。

Dim thdC = New Thread(New ParameterizedThreadStart(Sub() BoolH = Frm_ChkHash.MatchHash(Keyl))) 

か:後者は今、戻り値がないことを

Dim thdC = New Thread(New ParameterizedThreadStart(Function() 
     BoolH = Frm_ChkHash.MatchHash(Keyl) 
    End Function) 

ありません。

関連する問題