ProcessForUWP.UWP 0.0.4

dotnet add package ProcessForUWP.UWP --version 0.0.4                
NuGet\Install-Package ProcessForUWP.UWP -Version 0.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ProcessForUWP.UWP" Version="0.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ProcessForUWP.UWP --version 0.0.4                
#r "nuget: ProcessForUWP.UWP, 0.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ProcessForUWP.UWP as a Cake Addin
#addin nuget:?package=ProcessForUWP.UWP&version=0.0.4

// Install ProcessForUWP.UWP as a Cake Tool
#tool nuget:?package=ProcessForUWP.UWP&version=0.0.4                

Process for UWP

一种适用于 UWP 平台的 Process 方法

基于 @Silver-Fang 的项目 (Github)

LICENSE Issues Stargazers

UWP Desktop

目录

简介

本项目基于 @Silver-Fang 的项目 ProcessForUWP,与其不同的是,本项目利用了通信接口 AppServiceConnection 来进行应用间的通信,所以不用执行一次就弹一次 UAC,但是使用起来会比较麻烦。目前仍在开发当中,如果有兴趣欢迎加入。

如何使用

在你的解决方案中添加一个打包项目和一个空白桌面应用项目。在打包项目中引用你的 UWP 项目和桌面应用项目。在 UWP 项目中添加引用 ProcessForUWP.UWP,在桌面应用项目中引用 ProcessForUWP.Desktop

然后在打包项目的 Package.appxmanifest 中添加:

<Package
    ...
    xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" 
    IgnorableNamespaces="uap rescap desktop">
    ...
    <Applications>
        <Application>
            ...
            <Extensions>
                <uap:Extension Category="windows.appService">
                    <uap:AppService Name="ProcessForUWP.Delegate"/>
                </uap:Extension>
                <desktop:Extension Category="windows.fullTrustProcess" Executable="【桌面应用项目的路径,如:ProcessForUWP.Demo.Delegate\ProcessForUWP.Demo.Delegate.exe】" />
            </Extensions>
        </Application>
    </Applications>
    ...
</Package>

在 UWP 项目的 App.xaml.cs 中添加:

public sealed partial class App : Application
{
    ...
    protected override async void OnLaunched(LaunchActivatedEventArgs e)
    {
        Communication.InitializeAppServiceConnection();
        ...
    }

    /// <summary>
    /// Handles connection requests to the app service
    /// </summary>
    /// <param name="args">Data about the background activation.</param>
    protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
    {
        base.OnBackgroundActivated(args);
        Communication.OnBackgroundActivated(args);
    }
}

在桌面项目的 Program.cs 中添加:

internal class Program
{
    private static void Main(string[] args)
    {
        Communication.InitializeAppServiceConnection();
        ...
        EventWaitHandle WaitHandle = new AutoResetEvent(false);
        _ = WaitHandle.WaitOne();
    }
    ...
}

在解决方案配置管理器中,三个项目的平台需保持一致,建议都设为x64。生成都要勾选。部署只需勾选打包项目,UWP 项目和桌面项目都不需部署。
解决方案的启动项目应设为打包项目。

注意事项

  1. 具体使用方法请查看 Demo
  2. 请不要在应用初始化过程中新建 Process 类,虽然我已经做了未加载完成的判断,但是这个判断可能会占用了线程导致应用初始化无法完成,如果真的要在应用初始化时新建 Process 类,请把它挪到别的线程去,或者提出 issue 帮助我解决这个问题。

Star 数量统计

Star 数量统计

Product Compatible and additional computed target framework versions.
Universal Windows Platform uap10.0.15138 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.4 298 3/16/2023
0.0.3 552 2/26/2022
0.0.2 486 2/19/2022
0.0.1 452 2/19/2022