我有一個計時器事件,它調用類似於下面的代碼的東西。我的問題是,間歇性地,myObject
變量不保留bSuppress
或sSuppress
的值從前面的執行,我最終丟失文本。我有時可以運行我的代碼25次而沒有問題。然後,它會再次發生,每4次中有1次。任何幫助深表感謝。在定時器Tick事件中不保留對象的對象
謝謝
Private myObject as New someClass
Private sOutput as string
Private cQueue As New Collection
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Dim sCmd as string
sCmd=cQueue (1)
sOutput &= myObject.getText(sCmd)
cQueue.Remove(1)
end sub
Public Sub DoText(ByVal sText As String)
'received from a socket connection on a separate thread
cQueue.Add(sText)
End Sub
Public Class someClass
Private sSuppress as String
Private bSuppress as Boolean
Public function getText(sText as String) as String
'if we didn't end in a space during the last function call
'than prepend the previous input string
if bSuppress then
sText=sSuppress & sText
end if
If right(sText, 1)<>" " then
bSuppress=true
sSuppress=sText
exit function
end if
return sText
end function
End Class
發送的字符串更有可能不是你期望的,而是一個變量忘記其狀態 – Plutonix