gpt4 book ai didi

c# - 如何在按钮单击时调用异步?

转载 作者:行者123 更新时间:2023-11-27 22:58:19 26 4
gpt4 key购买 nike

我正在像下面那样在 clikc 上调用 asyn

  private List<SuggestedItemsInput> suggestedItemAsync()
{
OHDWebService OHDService = new OHDWebService();
List<SuggestedItemsInput> suggestedItemsList = OHDService.SaveSuggestedItems(ViewState["Body"].ToString(), hfdOrderRecordID.Value);
return suggestedItemsList;
}

点击

  protected async void imgbtnClaim_Click(object sender, EventArgs e)
{
try
{
Task<List<SuggestedItemsInput>> task = new Task<List<SuggestedItemsInput>>(suggestedItemAsync);
task.Start();
lblError.Text = "Please Wait. Proccessing...";
List<SuggestedItemsInput> suggestedItems = await task;
if (suggestedItems.Count > 0)
{

但它阻塞了 UI,并且会出现如下所示的错误 enter image description here

如何实现这一点?

最佳答案

像这样创建一个网络方法:

[WebMethod]
public async Task Yourmethod(string value)
{
value = "abc";
return value;
}

然后从您的前端使用 jquery 像这样点击此方法:

<script>
$(fucntion(){
$.ajax({
type: "POST",
url: "..../Yourmethod",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (data) { }
});
});

希望对您有所帮助。

关于c# - 如何在按钮单击时调用异步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54211962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com