@@ -179,12 +179,79 @@ they shut down, to refer to the updated framework package.
179
179
}
180
180
```
181
181
182
+ #### OnError
183
+
184
+ Additional behavior is available if an error occurs in ` DeploymentManager.Initialize() ` ,
185
+ per the following logic:
186
+
187
+ ```
188
+ DeploymentManager::Initialize(...)
189
+ {
190
+ // Only needed supported in packaged processes
191
+ IF IsPackagedProcess()
192
+ {
193
+ // We're not a packaged process. Don't call Initialize
194
+ return OK
195
+ }
196
+
197
+ // Do the initialization work
198
+ hr = _Initialize(...)
199
+ if FAILED(hr)
200
+ {
201
+ LogToEventLog(hr, ...)
202
+
203
+ // Should we pop the debugger?
204
+ IF IsDebuggerPresent()
205
+ {
206
+ DebugBreak()
207
+ }
208
+
209
+ // Should we pop some UI?
210
+ if options.OnError_ShowUI
211
+ {
212
+ MessageBox(...)
213
+ }
214
+ }
215
+ return hr
216
+ }
217
+ ```
218
+
219
+ Here's the previous example extended with the ` Show UI on error ` option:
220
+
221
+ ``` C#
222
+ if (DeploymentManager .GetStatus ().Status != DeploymentStatus .Ok )
223
+ {
224
+ // Create DeploymentInitializeOptions object and set ForceDeployment option
225
+ // to allow for force updating of the WinAppSDK packages even if they are currently in use.
226
+ // Also enable UI if an error occurs so a user can be told about the problem.
227
+ var deploymentInitializeOptions = new DeploymentInitializeOptions ();
228
+ deploymentInitializeOptions .ForceDeployment = true ;
229
+ deploymentInitializeOptions .OnErrorShowUI = true ;
230
+
231
+ // Initialize does a status check, and if the status is not OK it will attempt to get
232
+ // the WindowsAppRuntime into a good state by deploying packages. Unlike a simple
233
+ // status check, Initialize can sometimes take several seconds to deploy the packages.
234
+ // These should be run on a separate thread so as not to hang your app while the
235
+ // packages deploy.
236
+ var initializeTask = Task .Run (() => DeploymentManager .Initialize (deploymentInitializeOptions ));
237
+ initializeTask .Wait ();
238
+
239
+ // Check the result.
240
+ if (initializeTask .Result .Status != DeploymentStatus .Ok )
241
+ {
242
+ // The WindowsAppRuntime is in a bad state which Initialize() did not fix.
243
+ // Do error reporting or gather information for submitting a bug.
244
+ // Gracefully exit the program or carry on without using the WindowsAppRuntime.
245
+ }
246
+ }
247
+ ```
248
+
182
249
# API Details
183
250
184
251
``` C# (but really MIDL3)
185
252
namespace Microsoft .Windows .ApplicationModel .WindowsAppRuntime
186
253
{
187
- [contractversion (2 )]
254
+ [contractversion (3 )]
188
255
apicontract DeploymentContract{};
189
256
190
257
/// Represents the current Deployment status of the WindowsAppRuntime
@@ -221,6 +288,10 @@ namespace Microsoft.Windows.ApplicationModel.WindowsAppRuntime
221
288
/// WindowsAppSDK main and singleton packages will be shut down forcibly if they are
222
289
/// currently in use, when registering the WinAppSDK packages.
223
290
Boolean ForceDeployment ;
291
+
292
+ /// If not successful show UI
293
+ [contract (DeploymentContract , 3 )]
294
+ Boolean OnErrorShowUI ;
224
295
};
225
296
226
297
/// Used to query deployment information for WindowsAppRuntime
0 commit comments