Answered by:
promise from c# winmd cancel problem

Question
-
public static IAsyncOperation<string> getData(string url, string param) { return (IAsyncOperation<string>)AsyncInfo.Run((System.Threading.CancellationToken ct) => request(url, param)); } private static async Task<string> request(string url, string param) { HttpClient client = new HttpClient(); HttpContent httpContent = new StringContent(param); httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded"); var response = await client.PostAsync(url, httpContent); return response.content; }
var promise;
..
function reqData(){
if(promise)
promise.cancel();
..
promise = XXX.getData("http://www.eeeeee.com/nimabi.htm","a=1").then(onComplete,onerror,onprogress); ..
}
function onComplete(){
//something that i don't want to run repeatly
};
There is a page to search items,when I search it in different conditions, it will call reqData() again.
and render the result on the page.
so,my problem is : when i reqData too fast,i need to cancel the before oncomplete.but it seems do not work..
How to solve it? thx.
- Edited by dg11185 Friday, January 10, 2014 12:57 AM
Wednesday, January 8, 2014 10:07 AM
Answers
-
problem solved.
in getData()
ct.Register(() => ct.ThrowIfCancellationRequested());
- Marked as answer by Matt SmallMicrosoft employee, Moderator Friday, January 10, 2014 12:56 PM
Friday, January 10, 2014 9:18 AM
All replies
-
I don't understand - maybe I'm missing something since I don't do as much javascript - why would the onComplete run repeatedly? Please explain what's going on here.
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.Thursday, January 9, 2014 12:54 PMModerator -
Sorry for explaining it not clearly
There is a page to search items,when I search it in different conditions, it will call again reqData() again.
and render the result on the page.
so,my problem is : when i reqData too fast,i need to cancel the before oncomplete.but it seems do not work..
Friday, January 10, 2014 12:56 AM -
problem solved.
in getData()
ct.Register(() => ct.ThrowIfCancellationRequested());
- Marked as answer by Matt SmallMicrosoft employee, Moderator Friday, January 10, 2014 12:56 PM
Friday, January 10, 2014 9:18 AM