1

I wrote a C# Winform application that performs a task without user input and I want to run this program on a schedule (every day at 1 AM, for example). I want to set the program up on Azure so it runs on the cloud.

So far, I've successfully run C# Console applications in Azure Webjobs (a service under Azure Web Apps) and those work fine, but if I try to upload and run a Winform I get the error:

[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

in the logs. In the code, the error is specifically on a line like where I try to call webBrowser.Navigate function.

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

The URL itself is absolutely correct and it works when I run it on my desktop, but I guess something about changing URLs in a C# Webbrowser doesn't work.

So my question is, what Azure service will let me run a winform on a schedule? And if not Azure, I'll take Amazon or some other service. (I don't want to have my own dedicated physical computer to have to run this program. Thanks.

Kubera
  • 13
  • 2

1 Answers1

3

When running a webjob your application is running in a sandbox as described here where it says amongst other interresting things:

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).

So if you want to run an UI application you will have to do it on a VM. A Cloud Service would probably be the way to go or just a plain Virtual Machine.

jakobandersen
  • 1,339
  • 7
  • 9
  • Hmmmmm I was looking into virtual machines and it isn't really desirable. My company has certain features in Azure that are covered, and virtual machines and cloud services aren't one of them. I guess I'll accept this as an answer since you stated Winforms won't work under webjobs, though. – Kubera Mar 06 '16 at 00:15
  • So, You are telling me that I can call an http request on a VM and which will trigger my automation task? – Jamshaid K. Jul 20 '19 at 00:59