Incompatible signatures when spawning a thread with ThreadPool.QueueUserWorkitem
Error:
The 'Private Sub ProcessToolWork ()' method does not support signing with a WaitCallback Delegate Delegate (state as object).
What's the deal here? I have never experienced this error while creating a thread this way.
Here are my usual definitions:
Public Sub ProcessWork()
ThreadPool.QueueUserWorkItem(AddressOf ProcessToolWork)
End Sub
Private Sub ProcessToolWork()
End Sub
Is there anything wrong?
I also tried to create a new WaitCallback for this element, for example:
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ProcessToolWork))
source to share
WaitCallback takes an argument state
(of type Object
). Even if you ignore it, you should put it in your method signature:
Private Sub ProcessToolWork(ByVal ignored As Object)
End Sub
source to share
I just ran into this. Before doing "final" compilation, I turned Option Strict to "on" and this error appeared.
Note. This parameter is strict, not the Explicit option.
So, you only need to specify the Byval ignored As Object option if you are trying to compile with the Strict on option.
source to share