Some other instance has registered for this key, so we'll go ahead and do normal XAML initialization. If we successfully registered this instance, we can now just Var instance = AppInstance.FindOrRegisterInstanceForKey(key) string key = "Some-App-Defined-Key" // never unique. String key = Guid.NewGuid().ToString() // always unique. that is sometimes unique and sometimes not, depending on its own needs. In practice, the app should produce a key If the key is always non-unique, then the app will always redirect If the key is always unique, then the app will never redirect. Define a key for this instance, based on some app-specific logic. If (AppInstance.RecommendedInstance != null)Ī() the app can choose to redirect this activation to that instance instead. If the Windows shell indicates a recommended instance, then IActivatedEventArgs activatedArgs = AppInstance.GetActivatedEventArgs() logic for generating the key for this instance. First, we'll get our activation event args, which are typically richer rest of the example code and replace it with your custom code if you wish. Application.Start with a new App object. This example code shows how you could implement the required Main method to If the shell provides a preference, then you can redirect activation to that instance, or you can ignore it if you choose. The AppInstance.RecommendedInstance property represents the shell-provided preferred instance for this activation request, if there is one (or null if there isn't one). The template for Program.cs is shown below. The logic for redirecting activation goes in the Main function. The Multi-Instance Redirection UWP app template adds SupportsMultipleInstances to the package.appxmanifest file as shown above, and also adds a Program.cs (or Program.cpp, if you are using the C++ version of the template) to your project that contains a Main() function. To see it in action, watch this video about Creating multi-instance UWP apps. For example, if the app is launched to edit a file that is already being edited in another instance, you may want to redirect the activation to that instance instead of opening up another instance that that is already editing the file. It allows for customization in cases where you want to select whether a new instance of your app is launched or an instance that is already running is activated. Multi-instancing support for UWP apps goes beyond simply making it possible to launch multiple instances of the app. Note the namespace prefix desktop4 and iot2: only projects that target the desktop, or Internet of Things (IoT) projects, support multi-instancing. For example, perhaps you only want one instance at a time editing the same document, so you bring the instance that has that file open to the foreground rather than launching a new instance.īoth templates add SupportsMultipleInstances to the package.appxmanifest file. Two templates are installed: Multi-Instance UWP app, which provides the template for creating a multi-instance app, and Multi-Instance Redirection UWP app, which provides additional logic that you can build on to either launch a new instance or selectively activate an instance that has already been launched. Once you install the templates, they will be available in the New Project dialog under Visual C# > Windows Universal (or Other Languages > Visual C++ > Windows Universal). If you are creating a new multi-instance application, you can install the Multi-Instance App Project Templates.VSIX, available from the Visual Studio Marketplace. Since multi-instancing redirection is not supported for JavaScript applications, the AppInstance class is not useful for such applications. Multi-instancing is supported for JavaScript applications, but multi-instancing redirection is not.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |