2014-03-26 36 views
4

我有一個asp.net web表單項目這個方法:註冊與異步工作方法新pageasynctask這需要參數

private async Task SomeMethod(int accID){ // } 

我想這樣做在Page_Load,但我不知道該如何處理參數。

protected void Page_Load(object sender, EventArgs e) 
    { 
     RegisterAsyncTask(new PageAsyncTask(SomeMethod(int accID))); 

     // etc 
} 

回答

14

試試這個:

protected void Page_Load(object sender, EventArgs e) 
    { 
     RegisterAsyncTask(new PageAsyncTask(() => SomeMethod(accID: 1000))); 

     // etc 
} 
+0

感謝Noseratio。這有效,但是可以不爲accID指定「默認」值1000? –

+0

@AJ,你的意思是'新的PageAsyncTask(()=> SomeMethod())'?這是可能的。 – Noseratio

+0

我收到一條錯誤消息「方法沒有重載」SomeMethod'以0取參數「。不用擔心,我所做的是在我的方法中添加0的條件。 –