In the following example, I will make the WebBrowser control evaluate the VBScript expression "Now - 1" and embed the result in the WebBrowser's document.title so I can fetch it in C#:
WebBrowser wb = new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(
(object _sender, WebBrowserDocumentCompletedEventArgs _e) =>
{
MessageBox.Show(wb.Document.Title);
}
);
wb.DocumentText = @"
<HTML>
<HEAD>
<TITLE>Hello</TITLE>
<SCRIPT language=""VBScript"">
document.title = Now - 1
</SCRIPT>
</HEAD>
<BODY/>
</HTML>";
Obviously, this approach suffers from:
- the results are processed as strings
- the results require asynchronous handling
- poor code injection can lead to invalid results
- it may not perform well and could lead to creating a bottleneck in your app
My gut feeling is this approach is potentially worse than the approach you're currently using.