<method>没有重载匹配委托'System.Threading.WaitCallback

时间:2016-08-30 06:16:42

标签: c# vb.net multithreading

我是dot net的初学者。在将VB.Net代码转换为C#时,我遇到了一个问题。这是我的VB.Net代码......

Imports System.Threading

Dim waitCallInitialize As New WaitCallback(AddressOf ServiceInitialize)

ThreadPool.QueueUserWorkItem(waitCallInitialize)

Private Shared Sub ServiceInitialize()        

  WebServiceClient.CreateCalendarService()

  WebServiceClient.CreateClaimsService()

End Sub

我的等效c#代码是..

using System.Threading;


WaitCallback waitCallInitialize = new WaitCallback(ServiceInitialize);

ThreadPool.QueueUserWorkItem(waitCallInitialize);


private static  void  ServiceInitialize()
     {
         WebServiceClient.CreateCalendarService();
         WebServiceClient.CreateClaimsService();

     }

但这给了我错误:

  

“'ServiceInitialize'没有重载匹配委托'System.Threading.WaitCallback'

有人可以为此提供解决方案以及出错的原因吗?

1 个答案:

答案 0 :(得分:0)

WaitCallback Delegate期望对象状态。 ServiceInitialize必须是:

private static  void  ServiceInitialize(object state)
     {
         WebServiceClient.CreateCalendarService();
         WebServiceClient.CreateClaimsService();

     }