how to synchronize webservice calls in javascript - asp.net

I have a control application - using asp.net webservices.
I have a timer which does an asynchronous webservice call every 5 seconds to update the screen.There are also user buttons to refresh parts of the screen, also doing async webservice calls.
The issue is my screen get messy if a user webservice command is issued before the timer webservice response has arrived.
Basically, I want the user command to wait, if there is a pending async timer call in process. How do I synchronize between these calls in Javascript?
Thanks.

Is it possible to ignore the timed postback when a user postback occurs?
If so, set 2 flags (DontRequest and IgnoreNext) when the user does postback. When the user postback returns, unset DontRequest.
Your automated process would not start requests while DontRequest is set. If a response is received and IgnoreNext is set, ignore the response and unset the flag.

Related

Set time out for a web response from client side

I am calling a webservice to send sms to clients from my ASP.NET web app. Sometimes this webservice takes too much time to return a response, and this is causing problems with the next functions called in my app. So is there any way to add time out for the response from my app? In other words: can I add a time out so whenever the response time exceeds time out, my app continue working instead of waiting for a response?
How do you make the request ... HttpWebRequest? If this is the case you have a timeout property - https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout(v=vs.110).aspx
In case you don't care about the response, you can go with "Fire and forget" approach. You can find more information here - Simplest way to do a fire and forget method in C#?

Async WCF call not always successfully when silverlight app is closing

I have a silverlight app running in a browser as part of an overall ASP.NET website. I'm doing some event logging from it (tracking some UI click events and such).
I have a WCF service set up to create DB log records, and obviously the Silverlight app is calling it asynchronously.
This all works just fine, until I try to fire off a call to the logging service at the tail end of the app life. That is, when the user clicks a certain button, the silverlight calls some javascript on the website to redirects to another page, so the silverlight app closes, and then only sometimes do the last logger calls get through.
I am assuming it has something to do with the shutdown procedure of silverlight, and that it is a timing issue whereby sometimes the WCF channel is still open and the message gets through, and sometimes the channel closes and the logging doesn't occur.
Regardless of whether or not the logging occurs, the callback never fires for this last logger call.
As part of the handler for the last closing click event, the silverlight app calls this:
System.Windows.Browser.HtmlPage.Window.Eval("ViewEmployersPageWithMenu();")
Which, as I understand it, will trigger an exit of the silverlight app as the browser is navigating away from it.
Just before doing this, I fire off a simple logger call to my async wCF service.
I believe silverlight doesn't allow async service calls during its exit handling, is this the case? If there a different way I should be handling this o get that log call out successfully before the app closes?
If the logging is that important and considered an integral part of the application, you could hold off on calling the JavaScript function until the callback of the logging request. It may cause some delay in the execution of the redirect as it is now waiting for the WCF request to round-trip, but perhaps that is preferred to missing the log.
If you can replicate the issue, I would be curious to how Fiddler sees the series of requests (logging request and redirect request) when it works compared to when it does not. That may show that the browser is canceling the log request when it executes the redirect.

How to Kill Processes on hitting a button flex spark

When I send request to backend(java) its taking time to get the response, so If I hit cancel button, it only removing my title window but the process is still going on. So, after hitting cancel button how to stop Listening to the response immediately?
If remoteObject is using then we can cancel listening to the response by this small line
remoteObject.getOperation("serviceYouWantToStop").cancel();
You can stop listening for a response by removing the event listeners for the response. How you do this depends on the service you're using and how you call it, but generically like this:
myService.removeEventListener(ResultEvent.RESULT, myResultHandler);
myService.removeEventListener(FaultEvent.FAULT, myFaultHandler);
You should consider editing your question to provide those details. To actually stop the RemoteObject call, you can use the cancel() method of HTTPService; the disconnect() method on RemoteObject and a disconnect() method on WebService

ASP.NET process ajax request during batch process

I have ab asp.net form which does a few minutes of processing on postback(button click).I Know this is not ideal but I cannot run this process in an async thread as it uses a control reportviewer which is in Reqd only mode in non primary threads.
Given this limitation as the process is going on I would like to show the status at the client. For this I can fire off Ajax requests to the server to obtain processing status.But since the ASP.NET primary thread for the session is busy rendering the report using the reportviewer control the Ajax requests simply wait until all processing is over. Is there any way to periodically relinquish and regain control of primary thread .This we can allow it to reply to any ajax requests.
I have been researching this problem for a while now.All I need is to render a set of reports in background using the ReportViewer control and provide feedback at client
thanks
That makes no sense. New AJAX calls from the browser can and will be serviced by any of the available threads in the thread pool.
How are you posting the form? You would have to start the process with an AJAX request to generate the reports or else the browser will lock up waiting for the return from a normal form post. This would prohibit additional client side calls to be made to check status.

ASP.NET Asynchronous request callback

If I call a WebService Async using ASP.NET will the callback code still run even if the user is no longer physically on the page, or when the user leaves the page will the process terminate ?
Yes, if the user close the connection with the server, and your processing takes too much time, you get a throw of "connection close" and your process will terminate.
If you do not like that and you wish to keep the processing make a new thread that is not depend from the connection with the user, and synchronize it with the user return. If the user close the connection then the thread will finish normally, just you not show the results.

Resources