views:

262

answers:

2

The error is:

Method 'Private Sub ProcessToolWork()' does not have a signature compatible with delegate 'Delegate Sub WaitCallback(state As Object)'.

What's the deal here? I've never experienced this error spawning a thread in this fashion.

Here are my routine definitions:

Public Sub ProcessWork()
      ThreadPool.QueueUserWorkItem(AddressOf ProcessToolWork)
End Sub

Private Sub ProcessToolWork()

End Sub

See anything wrong?

I've also tried making a new WaitCallback for this item like so:

ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ProcessToolWork))
+3  A: 

WaitCallback takes a state argument (of type Object). Even if you ignore it, you have to put it in your method signature:

Private Sub ProcessToolWork(ByVal ignored As Object)

End Sub
Jon Skeet
Is this only necessary with Options Explicit turned on?
hypoxide
I don't know - but I *suspect* that with Option Explicit off it would just fail at execution time instead.
Jon Skeet
Huh. I'm vexed. In a previous project I queued a thread successfully in this fashion:Private Sub m_btnCollectData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles m_btnCollectData.Click Threading.ThreadPool.QueueUserWorkItem(AddressOf DoDataCollector)End SubPrivate Sub DoDataCollector() 'stuffEnd SubThe difference being that it was a web application.
hypoxide
Hmm. Not sure. Sounds like a bad idea to not implement the right signature though.
Jon Skeet