Delay the application closing of windows phone - windows-phone-7

Is it possible to delay the application closing event in windows phone. What i trying to achieve is, i need to send a web request(for sending the usage time of application) for achieving analytics in my application. So based on my current implementation before complete sending the request the main thread exits and application closes. What is the alternative to fix this issue. I cannot send the request in next application start(this fix i am not expecting)

You can use the Closingevent of the application.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff817008(v=vs.105).aspx
But you have a maximum of 10 seconds to send your data, after that os will kills your application.
The best scenario is to try to send the data and flag as send if it's ok before 10s, if not, you will need to send the data at the next launch.

Related

Does closing the Application browser window ends the processing that was happening in Spring MVC

In a Spring MVC app, if a page (browser window ) is closed while a functionality was running, will it stop the application and the processing that was happening or it will continue to happen at the server.
Suppose I have a functionality to export an excel report , I click the Export button. Now there are 2 cases :
Case 1 - If I initiate report generation without using thread , and close the window before report generation, would it throw the error/or abort the report generation OR would the process continue to happen on server and report will be downloaded?
Case 2) If I would have initiated report generation using a thread , and closed the window before report generation , would it throw the error /or abort the report generation OR would the thread continue to work in background and report will be downloaded?
The short answer is no, closing the browser tab or window will not affect the processing that is happening on the server (unless this processing also involves I/O with the client).
In general, Servlet containers (e.g. Tomcat) that host Spring MVC applications have a built-in thread pool to service the http requests. Once a request arrives, one of these threads will process it. If in the meantime, the TCP connection is closed by the client (which is what hopefully1 happens when closing a browser tab or window), the thread will not be notified or interrupted in any way. Therefore, any processing that might be happening on the server side will continue. I doesn't matter if you use another Thread to do the processing or not. The processing on the server will continue in both cases.
Since you are specifically asking about "downloding" a report file, here is some more info: Downloading involves I/O with the client. If you close the tab or browser before the download begins, the server will get an error as soon as it tries to write the data to the response. So the file will not be downloaded, data will not be transfered. If you close the tab after the download begins, the file will be downloaded normally. If the user cancels the file download, then again the server will get an error and data transfer will stop.
In any case, if the generation of the report happens before sending data back to the client, the generation will continue to work in the background, regardless of whether you use a Thread or not.
1 I say hopefully because the exact behavior depends on the OS / Device / browser. Closing the TCP connection would be the expected behavior.

My app Xamarin.Android stops responding

Developed an app using Xamarin.Android that periodically sends the location of the device through an API rest.
I randomly receive the following message in the UI: "My app is not responding, would you like to close it?"
I would like to know how to intercept the cause since I can not intercept it at development time.
Thank you.
Adding a crash reporter will definitely help you get to the bottom of your issue. Is there a chance that you are calling the REST service from the UI thread? If so, then if there is a network delay, it could "hang" the UI thread, this will result in Android killing the process because it thinks it is no longer working. To get around this issue use:
Task.Run(() => CallYourRESTService());
That way your UI thread won't be locked up. Just a suggestion. Of course it's hard to say without seeing a code sample.

Intercepting WM_ENDSESSION message

Is it possible to intercept WM_ENDSESSION message to prevent another application from receiving it?
I'd like to command that application to perform an additional action before Windows reboots or shuts down, and it's not possible to configure the application that way.
The application is screen recorder software, and it just throws away the video when Windows shuts down. I need to prevent that and save the video.
Is it possible to intercept WM_ENDSESSION message to prevent another application from receiving it?
Technically yes, using a message hook from SetWindowsHookEx(). Depending on the hook used, you can sometimes modify (not discard) messages to look like another messages, such as WM_NULL. However, in the case of WM_ENDSESSION, it is just a notification, not a request, so Windows is still going to continue shutting down no matter what applications do with that message.
I'd like to command that application to perform an additional action before Windows reboots or shuts down, and it's not possible to configure the application that way.
The application is screen recorder software, and it just throws away the video when Windows shuts down. I need to prevent that and save the video.
So, you don't actually want to avoid WM_ENDSESSION, you just want to delay the other app from processing it until after your action is performed first.
The best option would be to simply contact the recorder author and request a feature be added to save the video on system shutdown.
Beyond that, MSDN says the following:
Application Shutdown Changes in Windows Vista
By default, applications without any visible top-level windows will be given 5 seconds to handle WM_ENDSESSION before being terminated.
If your application may need more than 5 seconds to complete its shutdown processing in response to WM_ENDSESSION, it should call ShutdownBlockReasonCreate() in its WM_QUERYENDSESSION handler, and promptly respond TRUE to WM_QUERYENDSESSION so as not to block shutdown. It should then perform all shutdown processing in its WM_ENDSESSION handler.
This way, Windows will treat your application as if it had visible top-level windows and will give it 30 seconds to handle WM_ENDSESSION.
So, you could try using a message hook to intercept WM_QUERYENDSESSION and have it call ShutdownBlockReasonCreate() and return immediately, then intercept WM_ENDSESSION to invoke the video saving action and call ShutdownBlockReasonDestroy() when it is finished. Assuming, of course, that the recorder is throwing the video away in reply to WM_ENDSESSION and not WM_QUERYENDSESSION.
See MSDN for more info about how these two messages are handled by Windows:
Shutdown Changes for Windows Vista

background process and UI interaction

I am working on an application that is receiving XMPP notifications using the Matrix SDK. As well I am using async web service calls to receive an initial set of data from the server.
Now, I am aware that with Mango I can close the app or move it to the background and have a background task that is able to be run every 30 mins (or so) for 15sec max which obviosuly means the XMPP push isn't going to work in this scenario. Is there any way to get background apps to execute more frequently than this?
Failing that for the syncing process all I can do is every 30 mins use a web service call to get any updates and store into Isolated storage for my app to pick up when it's next run. But I believe I cannot use any UI from a background task so cannot tell the user of updates?
So, if I get an important message can I somehow override the slowness here and force my app to run and inform the user visibly that something has happened and he needs to look at it? Is this where push notifications come in?
You can use the ShellTile API to update the application's tile on the Start screen, or use the ShellToast API to show a toast to the user. Both of these can be configured to launch into a specific part of your application (deep-linking) when tapped.
If you need a constant monitoring/update/notification system for your application when it's not running, then using push notifications is probably the more appropriate approach.

How to abort shutdown in Windows (XP|Vista) programatically?

I want to be able to 1. detect (and, if needed 2. abort) OS shutdown from my application, preferably by using the Windows API.
I know that it is possible to abort shutdown manually using the command shutdown -a In the worst case, I could ShellExecute this, but I was wondering if there was a better way to prevent the shutdown programatically.
Maybe it would be enough to be notified programatically that the OS is about to shut down - how to do this?
From MSDN:
The WM_QUERYENDSESSION message is sent when the user chooses to end the session or when an application calls one of the system shutdown functions. If any application returns zero, the session is not ended. The system stops sending WM_QUERYENDSESSION messages as soon as one application returns zero.
So, my application's WindowProc now processes the WM_QUERYENDSESSION message and returns 0.
Didn't expect it to be this simple; as a bonus, it also works on Windows 2000.
In regards to 'simply' returning 0 to block a shutdown, it isn't as simple as that if you want to do it in the proper way. Especially on Vista. For example please also read http://msdn.microsoft.com/en-us/library/ms700677(VS.85).aspx

Resources