c# - 如何按计划在 Azure 中运行 C# Winform?

标签 c# winforms azure schedule webjob

我编写了一个 C# Winform 应用程序,该应用程序无需用户输入即可执行任务,并且我想按计划运行该程序(例如,每天凌晨 1 点)。我想在 Azure 上设置该程序,以便它在云上运行。

到目前为止,我已在 Azure Webjobs(Azure Web Apps 下的一项服务)中成功运行 C# 控制台应用程序,并且这些应用程序工作正常,但如果我尝试上传并运行 Winform,则会收到错误:

[03/03/2016 17:27:12 > 252553: ERR ] Unhandled Exception: System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
[03/03/2016 17:27:12 > 252553: ERR ]    at System.Windows.Forms.UnsafeNativeMethods.IWebBrowser2.Navigate2(Object& URL, Object& flags, Object& targetFrameName, Object& postData, Object& headers)
[03/03/2016 17:27:12 > 252553: ERR ]    at System.Windows.Forms.WebBrowser.PerformNavigate2(Object& URL, Object& flags, Object& targetFrameName, Object& postData, Object& headers)
[03/03/2016 17:27:12 > 252553: ERR ]    at System.Windows.Forms.WebBrowser.set_Url(Uri value)
[03/03/2016 17:27:12 > 252553: ERR ]    at WebBrowserTest.Form1.InitializeComponent()
[03/03/2016 17:27:12 > 252553: ERR ]    at WebBrowserTest.Form1..ctor()
[03/03/2016 17:27:12 > 252553: ERR ]    at WebBrowserTest.MainStartup.Main()
[03/03/2016 17:27:12 > 252553: SYS INFO] Status changed to Failed

在日志中。在代码中,错误具体出现在我尝试调用 webBrowser.Navigate 函数的行上。

Uri uri = new Uri("https://www.website.com");
webBrowser1.Navigate(uri);

URL 本身是绝对正确的,并且当我在桌面上运行它时它可以工作,但我猜想在 C# Web 浏览器中更改 URL 是行不通的。

所以我的问题是,哪种 Azure 服务可以让我按计划运行 winform?如果不是 Azure,我会选择亚马逊或其他一些服务。 (我不想拥有自己的专用物理计算机来运行这个程序。谢谢。

最佳答案

运行网络作业时,您的应用程序在沙箱中运行 described here除其他有趣的事情外,它还提到:

For the sake of radical attack surface area reduction, the sandbox prevents almost all of the Win32k.sys APIs from being called, which practically means that most of User32/GDI32 system calls are blocked. For most applications this is not an issue since most Azure Web Apps do not require access to Windows UI functionality (they are web applications after all).

因此,如果您想运行 UI 应用程序,则必须在虚拟机上执行。一个Cloud Service可能是可行的方法,或者只是一个普通的虚拟机。

关于c# - 如何按计划在 Azure 中运行 C# Winform?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35802525/

相关文章:

c# - 使用 LINQ-to-SQL 处理 where 子句中的空值

c# - 如何在调整窗体大小时移动面板中的所有控件?

c# - Windows 资源管理器 Crumb-Bar 控件

azure - Azure Blob 存储是否已备份

Azure cosmosdb 迁移工具多个集合

c# - 我如何使用 PrefixStyle 和 ProtoBuf-net 获取长度数?

c# - 在 Visual Studio Studio 中将所有函数/方法重命名为随机名称的方法

c# - 使用列模式从 SQL TABLE 创建 XML

c# - 从另一个线程更新列表框后,如何强制主GUI线程更新列表框?

Azure 函数主机 : worker process was unable to start