委托正在评估为DateTIme的字符串值?

时间:2016-04-27 14:19:56

标签: vb.net string datetime dictionary delegates

我正在使用来自线程类(实例化对象)的委托调用waitgif方法,在该方法中我维护自己的线程名称的字典。 (不要担心监控活动和封闭线程的方法 - 因为这是一种自定义方法,我实际上会进行大量的簿记)。

问题是发送给委托的字符串(" currentwaitgifname")正在被评估为DateTime并抛出异常,即使委托已经定义了发送给方法的字符串定义。我需要查看谓词吗?

         Public Delegate Sub ShowWaitGifDelegate(ByRef CurrentWaitGifName As String, ByVal onoff As Boolean, ByVal left As Integer, ByVal top As Integer)
         Public NumWaitGifs As Integer = 0
         Public currentwaitgifname As String = ""


         Dim main As Form1 = CType(Application.OpenForms(0), Form1)
         main.Invoke(New ShowWaitGifDelegate(AddressOf main.waitgifimg),  currentwaitgifname, False, 0, 0) ' Exception here, with string currentwaitgifname being evaluated against DateTime

         Public Sub waitgifimg(ByRef currentwaitgifname As String, ByVal onoff As Boolean, ByVal left As Integer, ByVal top As Integer)
            If currentwaitgifname = "" Then Exit Sub
            If onoff = True Then
                NumWaitGifs += 1
                currentwaitgifname = wgname + CStr(NumWaitGifs)
                Call addthreadtodic(currentwaitgifname)
            End If
            If onoff = False Then
                Call removethreadfromdic(currentwaitgifname)
            End If
        End Sub

        Public Sub addthreadtodic(ByVal currentwaitgifname)
            If dicWaitgifThreads.ContainsKey(currentwaitgifname) = False Then
                dicWaitgifThreads.Add(currentwaitgifname, "")
            End If
            My.Settings.dicWaitgifThreads.Add(currentwaitgifname.ToString)
            My.Settings.Save()
        End Sub

        Public Sub removethreadfromdic(ByVal currentwaitgifname)
            If currentwaitgifname = "" Then Exit Sub
            For Each kvp As KeyValuePair(Of String, String) In dicWaitgifThreads
                dicWaitgifThreads.RemoveAt(kvp.Key.ToString)
                My.Settings.dicWaitgifThreads.RemoveAt(kvp.Key)
                GoTo savesettings
            Next
    savesettings:
            My.Settings.Save()
        End Sub

0 个答案:

没有答案