System.Windows.Forms.WebBrowser inside Asp.net WebForm DocumentCompleted not fired
Yeah some people would say "Are you crazy using winforms controls inside asp forms"... and I think they are right. But I would say.. "I'm not the only one!!, take a look"
http://www.eggheadcafe.com/tutorials/aspnet/b7cce396-e2b3-42d7-9571-cdc4eb38f3c1/build-a-selfcaching-asp.aspx
So...
Doing some kind of stuff like the previous link. I did the following:
using System; using System.Threading; using System.Windows.Forms;
namespace XXXX.aspx.Print { public partial class Drucker : System.Web.UI.Page { private ManualResetEvent mre = new ManualResetEvent(false);
protected void Page_Load(object sender, EventArgs e)
{
Threading();
}
private void Threading()
{
Thread t = new Thread(new ThreadStart(GoAhead));
t.SetApartmentState(ApartmentState.STA);
t.Start();
mre.WaitOne();
t.Abort();
}
private void GoAhead()
{
DateTime time = DateTime.Now;
WebBrowser webBrowser = new WebBrowser();
webBrowser.Navigate(Request.UrlReferrer.ToString());
webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
while (true)
{
Thread.Sleep(0);
TimeSpan elapsedTime = DateTime.Now 开发者_JS百科- time;
if (elapsedTime.Seconds >= 13)
{
mre.Set();
}
System.Windows.Forms.Application.DoEvents();
}
}
void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser webBrowser = (WebBrowser)sender;
if (e.Url.AbsolutePath != webBrowser.Url.AbsolutePath) return;
webBrowser.Print();
}
}
}
Now...
the DocumentCompleted event is not fired (neither ProgressChanged) and I've tried the next:
- Add the library MsHtml.dll to my project and place the file into my lib folder... I did it... No changes.
- Try to handle the state of the WebBrowser.ReadyState... I did it... No changes (Actually after receive the WebBrowserReadyState.Complete I tried to print the document with webBrowser.Print(); but I receive a weird IE pop up telling me: "'dialogArguments.__IE_PrintType' is Null or a not an object'"... ok so doing some research I got: a microsoft topic about dcomcnfg and some com security settings I did it... No changes. ...
By the way I´m working in 64bits, Win7... So before I format the whole computer... Any suggestions?
WebBrowser is never inplace-activated by its ActiveX container, which you don't have. Try put it on a form first.
By the way, you know you are in the unsupported territory when you use WinInet, the network layer of webbrowser control, in a Windows Service, right?
精彩评论