簡體   English   中英

我如何用c#中的bool方法解決這個錯誤線程

[英]how i can solve this error thread with bool method in c#

我的Windows服務項目中的這段代碼給我編譯錯誤預期帶有void InitializeBridge簽名的方法

      static void Main(string[] args)
      {
            if (args != null && args.Length == 1 && args[0].StartsWith("-c"))
            {
                 BridgeService bridgeService = new BridgeService();

                 if (Vytru.Platform.Bridge.Configuration.LicenseValidetor.ValidCountAndTypeDevices())
                 {
                      Console.WriteLine("Bridge Service Is Started ......");

                      var daemonThread = new Thread(SharedData.InitializeBridge);
                      daemonThread.Start();
                 }
                 else
                 {
                      Console.WriteLine("Bridge Service License is not Valid ...");
                 }
            }
            else
            {
                 ServiceBase[] ServicesToRun;
                 ServicesToRun = new ServiceBase[] 
                  { 
                      new BridgeService() 
                  };
                 ServiceBase.Run(ServicesToRun);
            }
      }

這是我的靜態方法InitializeBridge ..

      public static bool InitializeBridge()
      {
            return DeviceList.All(CreateBridgeConnection);

      }

你不能從一個返回bool的方法創建一個ThreadStartParameterizedThreadStart 這些是可以傳遞給Thread構造函數的兩個委托類型,這里沒有適用的方法組轉換。

如果你不關心返回值(這看起來很奇怪),最簡單的方法可能是使用lambda表達式來調用它並忽略返回值:

var daemonThread = new Thread(() => SharedData.InitializeBridge());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM