我的經驗問題,呼籲使用(Windows Phone的應用程序)使用多的HttpWebRequest調用定時器web服務無法正常工作
HttpWebRequest.Create(new Uri("http://x.x.x.x/webservice.svc/Getnewtick")) as HttpWebRequest
我用內部功能這一請求在計時器相同的URL和該功能的工作,我有檢查使用提琴手的流量,我發現第一個請求工作,但第二個不會發送和新的請求到服務器,你可以告訴我(注意我已經把消息框內的功能,它的出現很好的時間,這意味着定時器工作正常)
這是我的代碼根據您的要求: -
private void FireRequest3(Object sender, EventArgs args)
{
MessageBox.Show("hello");
var request = HttpWebRequest.Create(new Uri("http://x.x.x.x/webservice.svc/Getnewtick")) as HttpWebRequest
request.Method = "GET";
request.CookieContainer = cookieJar;
request.BeginGetResponse(ar =>
{
HttpWebRequest req2 = (HttpWebRequest)ar.AsyncState;
using (var response = (HttpWebResponse)req2.EndGetResponse(ar))
{
using (Stream stream = response.GetResponseStream())
{
using (var reader = new StreamReader(stream))
{
var outerRoot2 = JsonConvert.DeserializeObject<OuterRootObject2>(reader.ReadToEnd());
var root = JsonConvert.DeserializeObject<RootObject2>(outerRoot2.d);
DispatchInvoke(() =>
{
foreach (var Symbols1 in root.Symbols)
{
foreach (var nnn in DataReceivedCollection)
{
var symbolIDintold = Convert.ToInt16(nnn.symid);
var symbolIDintnew = Convert.ToInt16(Symbols1.I);
var BidStr = Convert.ToString(Symbols1.B);
var AskStr = Convert.ToString(Symbols1.B);
if (symbolIDintold == symbolIDintnew)
{
nnn.textSecond = BidStr;
nnn.textThird = AskStr;
}
}
}
});
}
}
}
}, request);
}
並將其與計時器啓動按鈕是: -
private void Button_Click_2(object sender, EventArgs e)
{
DispatcherTimer newTimer = new DispatcherTimer();
newTimer.Interval = TimeSpan.FromSeconds(3);
newTimer.Tick += FireRequest3;
newTimer.Start();
}
您可以加入實際執行請求的代碼(定時器)? – silent
你可以現在檢查,謝謝 – Jordan
你有沒有暗示的建議? – Jordan