0
我打開窗體時使用C#中的RestSharp調用Restful API,但在調用此GUI時會打開並鎖定。RestSharp異步API - 更新GUI
只是想知道我在做什麼錯?
我已經調用而BeginInvoke之間變化,但沒有運氣 - 調試輸出,似乎第一&第二調用之間的某處掛電話
public void show_members(String url, String api_key, String card_number)
{
member_numbers.Clear();
st_url = url;
st_api_key = api_key;
st_card_number = card_number;
var client = new RestClient(url);
var request = new RestRequest("pendingmembers?api_key={api_key}", Method.GET);
request.AddUrlSegment("api_key", api_key);
Debug.WriteLine(url + "pendingmembers?api_key=" + api_key);
// async with deserialization
var asyncHandle = client.ExecuteAsync<PendingMembers>(request, response =>
{
Debug.WriteLine(response.Data.status);
if (response.Data.status == "OK")
{
//Company ID is Correct
//Dispatcher.Invoke((Action)() => {cb_MemberList.Items.Clear();});
if (this.InvokeRequired)
{
this.Invoke((Action)(() =>
{
cb_MemberList.Items.Clear();
}));
}
else
{
cb_MemberList.Items.Clear();
}
//Debug.WriteLine(response.Data.members);
foreach(var member in response.Data.members)
{
Debug.WriteLine(member.full_name);
member_numbers.Add(member.member_id);
if (this.InvokeRequired)
{
this.Invoke((Action)(() =>
{
Debug.WriteLine(member.full_name);
cb_MemberList.Items.Add(member.full_name);
}));
}
else
{
Debug.WriteLine(member.full_name);
cb_MemberList.Items.Add(member.full_name);
}
}
Application.DoEvents();
}
});
}