2016-10-01 21 views
1

我有WCF服務公開,驗證參數並真實/錯誤地返回並運行後臺線程來處理結果。對於我曾嘗試與HostingEnvironment.QueueBackgroundWorkItem做到這一點,但它給了我下面的錯誤:下面後臺線程與WCF中的HostingEnvironment.QueueBackgroundWorkItem

Operation is not valid due to the current state of the object.

代碼給出:

public class SearchService : ISearchService 
{ 
    public async Task<bool> SearchAsync(UserSearch search, string email) 
    { 
     //Some operations 
     var searchManager = new SearchManager(); 
     HostingEnvironment.QueueBackgroundWorkItem(ct => searchManager.PerformSearch(search, email)); 
     return true; 
    } 
} 
+1

任何codez顯示? [MCVE] – MickyD

回答

0

我得到了它的工作如下:

var thread = new Thread(
       async() => 
       { 
        await searchManager.PerformSearch(search, email); 
       }) {IsBackground = true}; 

      thread.Start(); 

任何更好的選擇,請讓我知道。