Home > Net >  C # write asynchronous? To achieve the popup window to invoke the web service
C # write asynchronous? To achieve the popup window to invoke the web service

Time:10-24




In another way so that calls can be called a main implementation when loading wait for window
This. SplashScreenManager1. ShowWaitForm ();

Task Xmlstring=GetPatientList (pid);

This. SplashScreenManager1. CloseWaitForm ();

CodePudding user response:

What should we do with an error?

CodePudding user response:

You this is not a DCLInterface asynchronous method, if the method is an asynchronous method, load before you only need to await the pop-up box, await closed after loading frame,

CodePudding user response:

Give you an asynchronous method
 public static class CallWebAPI 
{
Public static async Task APIPost (url string, the string data)
{
The string result=string. The Empty;
//set HttpClientHandler AutomaticDecompression
(1) {var handler=new HttpClientHandler AutomaticDecompression=DecompressionMethods. GZip};
//create the HttpClient (note that the incoming HttpClientHandler)
Using HTTP=new HttpClient (var (handler))
{
//using FormUrlEncodedContent do HttpContent
Var content=new FormUrlEncodedContent (new Dictionary ()
{
//pass a single value
{" ", the data}//keys must be empty
//transfer object
//{" name ", "hello"},
//{" age ", "16"}
});

//await an asynchronous response to
Var response=HTTP. Await PostAsync (url, the content);
//to ensure the success of the HTTP status value
The response. EnsureSuccessStatusCode ();
//await asynchronous read last JSON (note that the gzip automatically extract had been made, and because of the above AutomaticDecompression=DecompressionMethods. Gzip)
Result=await the response. The content. ReadAsStringAsync ();
}
return result;
}

The static async void APIGet (string url)
{
//create the HttpClient (note that the incoming HttpClientHandler)
(1) {var handler=new HttpClientHandler AutomaticDecompression=DecompressionMethods. GZip};

Using HTTP=new HttpClient (var (handler))
{
//await an asynchronous response to
Var response=HTTP. Await GetAsync (url);
//to ensure the success of the HTTP status value
The response. EnsureSuccessStatusCode ();

//await asynchronous read last JSON (note that the gzip automatically extract had been made, and because of the above AutomaticDecompression=DecompressionMethods. Gzip)
Console. WriteLine (await the response. The content. ReadAsStringAsync ());
}
}
}

CodePudding user response:

refer to the second floor morning to evening reply:
you this is not a DCLInterface asynchronous method, if the method is an asynchronous method, load before you only need to await the pop-up box, await closed after loaded box,
DCLInterface is a web service method

CodePudding user response:

DCLInterface not asynchronous method, cannot use await, you can then use the async DCLInterface do the encapsulation, again to encapsulate function USES await,

Ps: loading window with asynchronous relationship? Not all scenarios should use asynchronous, otherwise easy to simple complication,
  •  Tags:  
  • C#
  • Related