示例#1
0
        public static Task <bool> LaunchApplicationFromAUMIDAsync(string AppUserModelId, params string[] PathArray)
        {
            if (PathArray.Length > 0)
            {
                return(ExecuteOnSTAThreadAsync(() =>
                {
                    List <ShellItem> SItemList = new List <ShellItem>(PathArray.Length);

                    try
                    {
                        if (new Shell32.ApplicationActivationManager() is Shell32.IApplicationActivationManager Manager)
                        {
                            foreach (string Path in PathArray)
                            {
                                SItemList.Add(new ShellItem(Path));
                            }

                            using (ShellItemArray ItemArray = new ShellItemArray(SItemList))
                            {
                                Manager.ActivateForFile(AppUserModelId, ItemArray.IShellItemArray, "Open", out _);
                            }

                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    catch
                    {
                        return false;
                    }
                    finally
                    {
                        SItemList.ForEach((Item) => Item.Dispose());
                    }
                }));
            }
            else
            {
                return(LaunchApplicationFromAUMIDAsync(AppUserModelId));
            }
        }