Answered by:
How does Windows detects the app has not started in the appropriate time?

Question
-
My app is quickly returning from app.activated handler (even using a promise, as in the samples), yet Windows thinks my app takes too long to start.
Causing this issue is this code:
extractResourcesAsync = function() { if (!resourcesChecked) { return localFolder.createFolderAsync('resources', CreationCollisionOption.openIfExists).then(function(resourcesFolder) { var stream; stream = RandomAccessStreamReference.createFromUri("resources.zip".toAppPackageUri()); return runtime.zip.ZipArchive.createFromStreamReferenceAsync(stream).then(function(archive) { var fileInformationFactory, fileQuery, queryOptions; queryOptions = new Windows.Storage.Search.QueryOptions(); queryOptions.folderDepth = Windows.Storage.Search.FolderDepth.deep; fileQuery = resourcesFolder.createFileQueryWithOptions(queryOptions); fileInformationFactory = new FileInformationFactory(fileQuery, Windows.Storage.FileProperties.ThumbnailMode.listView, 0); return fileInformationFactory.getFilesAsync().then(function(existingFiles) { return _.filter(archive.files, function(f) { return f.isDirectory === 0; }).sequentialEachAsync(function(archivedFile) { var existingFile, extractFileAsync, replacedName, _i, _len; extractFileAsync = function() { doo.log.trace("Extracting " + archivedFile.filename + " to resources folder"); return archive.extractFileToFolderAsync(archivedFile.filename, resourcesFolder); }; replacedName = archivedFile.filename.replace(/\//g, '\\'); for (_i = 0, _len = existingFiles.length; _i < _len; _i++) { existingFile = existingFiles[_i]; if (existingFile.path.indexOf(replacedName) === existingFile.path.length - replacedName.length) { return existingFile.getBasicPropertiesAsync().then(function(basicProperties) { if (basicProperties.size !== archivedFile.uncompressedSize) { return extractFileAsync(); } }); } } return extractFileAsync(); }); }); }); }).then(function() { return resourcesChecked = true; }); } else { return WinJS.Promise.wrap({}); } };
which is called in one JS script file using
WinJS.Promise.timeout(5000).done(function() { return extractResourcesAsync(); });
The resource extraction is very cpu intense according to the profiler. But the activated handler has long returned (takes only a couple of msecs) and the app is already working and very responsive. Yet, Windows decides to shut it down, cause it did not start properly.
- Edited by phil_ke Friday, October 12, 2012 5:31 PM
Friday, October 12, 2012 5:30 PM
Answers
-
Hi Phil,
The OS is shutting you down because you are taking to long to get that first page up.
There is a sample on how to handle this here:
http://code.msdn.microsoft.com/windowsapps/Splash-screen-sample-89c1dc78
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Monday, October 15, 2012 3:50 PM
- Marked as answer by Song Tian Thursday, October 18, 2012 6:42 AM
Monday, October 15, 2012 3:50 PMModerator
All replies
-
Hi Phil,
The OS is shutting you down because you are taking to long to get that first page up.
There is a sample on how to handle this here:
http://code.msdn.microsoft.com/windowsapps/Splash-screen-sample-89c1dc78
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Monday, October 15, 2012 3:50 PM
- Marked as answer by Song Tian Thursday, October 18, 2012 6:42 AM
Monday, October 15, 2012 3:50 PMModerator -
Jeff, did you miss this part of my message:
"But the activated handler has long returned (takes only a couple of msecs) and the app is already working and very responsive. Yet, Windows decides to shut it down, cause it did not start properly."
You can already use the app. Its snappy, its working. I also using a promise as stated in your sample code.
- Edited by phil_ke Monday, October 15, 2012 3:56 PM
Monday, October 15, 2012 3:55 PM -
That is the only test for startup. You would need to provide a repro of this to investigate further.
-Jeff
Jeff Sanders (MSFT)
Monday, October 15, 2012 6:08 PMModerator