小错误(线程) [英] A small error(thread)
问题描述
我不断收到以下错误:
"委托''system.windows.forms.methodinvoker"
需要"AddressOf"表达式或
lambda表达式是其构造函数的唯一参数."
请帮帮我.
-----------我的代码------------------
I keep getting the following error:
""Delegate ''system.windows.forms.methodinvoker''
requires an ''AddressOf''expression or
lambda expression as the only argument to its constructor.""
Please Help Me.
-----------my code------------------
Public Sub search()
Try
cmdoledb.CommandText = "SELECT NAME FROM table1 WHERE ID=" & CInt(txtid.Text)
cmdoledb.CommandType = CommandType.Text
cmdoledb.Connection = cnnoledb
Dim rdroledb As OleDbDataReader = cmdoledb.ExecuteReader
While rdroledb.Read = True
updatetext(rdroledb.Item(0).ToString)
Thread.Sleep(2000)
tictac()
End While
t1.Abort()
Catch ex As Exception
MsgBox(ex.Message)
End Try
cmdoledb.Dispose()
End Sub
Private Sub updatetext(ByVal text)
If Me.InvokeRequired Then
Me.Invoke(Me.Invoke(New MethodInvoker(AddressOf updatetext, text)))
Else
txtnam.Text &= text
End If
End Sub
推荐答案
您不理解错误中的英语吗?那是问题吗?
MethodInvoker没有允许多个参数的重载.该错误告诉您一切:
Do you not understand the English in the error? Is that the problem?
MethodInvoker does not have an overload that allows for multiple parameters. The error tells you everything:
删除"system.windows.forms.methodinvoker"
需要"AddressOf"表达式或
lambda表达式作为其构造函数的 only 参数.
Delegate ''system.windows.forms.methodinvoker''
requires an ''AddressOf''expression or
lambda expression as the only argument to its constructor.
MethodInvoker仅接受一个参数.如果要传递参数,请在调用..."中执行此操作,如下所示:
MethodInvoker only takes one argument. If you want to pass a parameter, you do that in the Invoke...as in:
Me.Invoke(New MethodInvoker(AddressOf updatetext),New Object(){text})
克里斯蒂安(Christian)是对的...我有什么事?两次调用?在进行此操作之前,您需要先了解自己在写什么.
and Christian is right...what''s up with Me.Invoke twice? You need to try to understand what you''re writing before doing it.
您的基本问题是无知和文盲的结合.我假设,尽管您没有告诉我们,但这行是错误的:
Your basic issue is a combination of cluelessness and illiteracy. I assume, despite you not telling us, that this line is the error:
Me.Invoke(Me.Invoke(New MethodInvoker(AddressOf updatetext,text)))
Me.Invoke(Me.Invoke(New MethodInvoker(AddressOf updatetext, text)))
你为什么打给我两次调用?是因为
一个-这实际上是对的,我.调用返回与AddressOf
b-在网上盲目复制代码后出现错误,因此请在这里提出问题,因为您无法使用google,无法阅读并且不知道自己在做什么(因此无法诊断问题) ?
哦,您的代码仍然很糟糕-表示层中的SQL,假定文本框包含int的假设,等等.如果有人在该文本框中键入文本会发生什么?
Why are you calling me.invoke twice ? Is it because
a - this is actually right, me.invoke returns the same thing as AddressOf
b - you get an error after copying code blind off the web, so ask here because you can''t use google, can''t read, and have no idea what you''re doing ( and therefore cannot diagnose the problem ) ?
Oh, your code is still terrible - SQL in the presentation layer, the assumption that a textbox contains an int, etc. What happens if someone types text in to that textbox ?
这篇关于小错误(线程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!