I'm using Azure app service to host an API. The API contains a dummy method that calls a normal Webbroswer. Below is code :
[HttpGet]
[Route("c")]
public string GetCorrection()
{
string result = "NoResults";
ClassLibrary2.Class2 class2 = new ClassLibrary2.Class2();
try
{
Thread thread = new Thread(new ThreadStart(() =>
{
class2.Browse();
}));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
catch (Exception ex)
{
return ex.ToString();
}
return result;
}
public string Browse()
{
using (WebBrowser browser = new WebBrowser())
{
browser.ScrollBarsEnabled = false;
browser.ScriptErrorsSuppressed = true;
browser.AllowNavigation = true;
browser.Navigate("https://en.wikipedia.org/wiki/Wiki");
return browser.DocumentTitle;
}
}
}
Eveything works normaly localy.
But once i publish it to Azure, 502 error occurs.
If i remove the
browser.Navigate("https://en.wikipedia.org/wiki/Wiki");
line, no error occurs.
Any idea ?
I'm having doubts that's it's related to the System.Windows.Forms event.
Thanks in advance,