在.NET中調用函數時可以設置超時值嗎?我使用稱爲SharpBox的第三方組件來循環一組Dropbox帳戶,並將內容拉入服務器上的給定文件夾。在.NET中調用函數時設置超時值
昏暗itemsDownload爲整數= pollSingleDropboxAccount(帳戶)
function pollSingleDropboxAccount(accountID as integer) as integer
//Utilises Sharpbox to download the files and return the count
//In here a connection is established using the SharpBox.dll
//but never gets closed or throws an exception leaving the
//function to hang indefinitely
end function
Sharpbox使用HttpWebRequest的幕後接觸收存箱API,但似乎默認超時到無限的,並且這個值不能被重寫。我用SharpBox提出了一項功能要求,但我正在尋找一些我們可以在此同時使用的解決方法。
爲了規避這個問題,我想知道我們是否可以在打電話給'pollSingleDropboxAccount'函數後放棄一些東西放棄說5分鐘後?
你可以使用.NET 4.0+以上的TPL嗎? – Alex 2013-02-25 10:49:17
[Implement C#Generic Timeout]的可能的重複(http://stackoverflow.com/questions/299198/implement-c-sharp-generic-timeout) – sloth 2013-02-25 10:57:35
我們使用.NET 4,所以是的這是可行的。我現在在圖書館看更詳細的 – QFDev 2013-02-25 11:34:22