在 .NET Framework 中我们可以直接用:
System.Diagnostics.Process.Start("mailto:Leenrung@outlook.com?subject=主题")
这样的方法调用Windows邮件客户端,或者用https协议打开某个网页。但在 .NET Core 中,此方法会失败,提示系统找不到指定的文件。
解决方法也很简单,你需要显式设置UseShellExecute=True:
System.Diagnostics.Process.Start(New ProcessStartInfo("mailto:Leenrung@outlook.com?subject=主题") With {.UseShellExecute = True})
这是因为Framework中UseShellExecute默认True,而在Core中默认False。微软修改此默认行为的理由,可能是false情形下性能更高,或者是出于Core跨平台的考虑,因为mailto这种协议是Windows特定的。实际上,此属性在 Framework, Core 和UWP上的行为均不相同,详见官方文档:
ProcessStartInfo.UseShellExecute 属性https://learn.microsoft.com/zh-cn/dotnet/api/system.diagnostics.processstartinfo.useshellexecute在UWP上,此属性必须设为false,不允许使用true。