C# 方法在2秒后调用 httpresponsemessageresponse=client.postsjsonasync(ConfigurationManager.AppSettings[Constants.BidApiBaseURL],objClientBidRequest)。结果; if(response.StatusCode.ToString()=“OK”) { //2秒后发送投标结果请求 字符串bidContent=“”; 对于(int i=1;i
您可以使用 或 你可以用 你可以用 或 你可以用C# 方法在2秒后调用 httpresponsemessageresponse=client.postsjsonasync(ConfigurationManager.AppSettings[Constants.BidApiBaseURL],objClientBidRequest)。结果; if(response.StatusCode.ToString()=“OK”) { //2秒后发送投标结果请求 字符串bidContent=“”; 对于(int i=1;i,c#,C#,您可以使用 或 你可以用 你可以用 或 你可以用 使用Thread.sleep方法在2秒后调用callnext语句 // Create a timer with a ten second interval. aTimer = new System.Timers.Timer(10000); // Hook up the Elapsed event for the timer. aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); //
使用Thread.sleep方法在2秒后调用callnext语句
// Create a timer with a ten second interval.
aTimer = new System.Timers.Timer(10000);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 2000;
aTimer.Enabled = true;
httpresponsemessageresponse=client.postsjsonasync(ConfigurationManager.AppSettings[Constants.BidApiBaseURL],objClientBidRequest)。结果;
if(response.StatusCode.ToString()=“OK”)
{
//2秒后发送投标结果请求
《睡眠》(2000年);
字符串bidContent=“”;
for(inti=1;i使用Thread.sleep方法在2秒后调用next语句
// Create a timer with a ten second interval.
aTimer = new System.Timers.Timer(10000);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 2000;
aTimer.Enabled = true;
httpresponsemessageresponse=client.postsjsonasync(ConfigurationManager.AppSettings[Constants.BidApiBaseURL],objClientBidRequest)。结果;
if(response.StatusCode.ToString()=“OK”)
{
//2秒后发送投标结果请求
《睡眠》(2000年);
字符串bidContent=“”;
对于(int i=1;i您应该在服务调用中使用wait
语句。这样,您的程序将等待服务响应:
HttpResponseMessage response = client.PostAsJsonAsync(ConfigurationManager.AppSettings[Constants.BidApiBaseURL], objClientBidRequest).Result;
if (response.StatusCode.ToString() == "OK")
{
// Send request after 2 second for bid result
Thread.Sleep(2000);
string bidContent = "<iframe src=maps.google.com?gps=....></iframe>";
for (int i = 1; i <= 4; i++)
{
lstExpertBidResponse.Add(
new BidResponse(
objClientBidRequest.RequestId.ToString(),
bidContent,
i.ToString(),
"W" + i.ToString(),
GetFeedBackScore("W" + i.ToString()),
GetExpertID("W" + i.ToString())
));
}
}
在此处查看异步编程:您应该在对服务的调用中使用wait
语句。这样,您的程序将等待服务响应:
HttpResponseMessage response = client.PostAsJsonAsync(ConfigurationManager.AppSettings[Constants.BidApiBaseURL], objClientBidRequest).Result;
if (response.StatusCode.ToString() == "OK")
{
// Send request after 2 second for bid result
Thread.Sleep(2000);
string bidContent = "<iframe src=maps.google.com?gps=....></iframe>";
for (int i = 1; i <= 4; i++)
{
lstExpertBidResponse.Add(
new BidResponse(
objClientBidRequest.RequestId.ToString(),
bidContent,
i.ToString(),
"W" + i.ToString(),
GetFeedBackScore("W" + i.ToString()),
GetExpertID("W" + i.ToString())
));
}
}
看看这里的异步编程:我使用了一个API服务,它接受我的json对象,如果状态返回OK,那么我需要在2秒钟后调用一个方法。使用Thread.Sleep(2000)怎么样?我已经使用了一个API服务,它接收我的json对象,如果状态返回OK,那么我需要在2秒钟后调用一个方法。使用Thread.Sleep(2000)怎么样?谢谢你的指导,我会遵循它。谢谢你的指导,我会遵循它。
var task = await client.PostAsJsonAsync(
ConfigurationManager.AppSettings[Constants.BidApiBaseURL],
objClientBidRequest);
// wait for service to complete
HttpResponseMessage response = task.result;
if (response.StatusCode.ToString() == "OK")
// etc etc