C# multithreaded windows form with multiple embedded web browsers - c#

There is an open source windows form client for Xibo that contains embedded web browsers. The problem is that while one web browser is getting busy, the other browsers and controls in the form can't respond and they actually pause. So I thought maybe it is a good idea to have one thread for each web browser with it's own application message loop. But it seems unsafe to add controllers created in different threads to a single form. In fact I was lucky to have some browsers in different threads by a few lines of code refactor before I realized it actually should not work at all!
Is it a good way to make it possible? What is the best solution to make such an application multithreaded with minimum coding?

Related

Taking screenshots of partially hidden windows from .NET WPF applications

I am working on a program that starts several other c# WPF applications and checks wether there are errors (using .NET Automation Services / UITesting).
One of the requirements of it is to take a screenshot of the main window and to put it into a word document. I alread got it working quite fine when it´s one application at a time (using code from this site: http://www.developerfusion.com/code/4630/capture-a-screen-shot/) , but as soon as i am using parallelism (say, checking 5 applications in a parallel manner), i am running into the problem that the screenshots of the windows may be overlapped by other windows that just popped up or that are always brought to the front (e.g. splash screens). Bringing the window to the front does not really help.
There was an older similar thread not directly regarding to WPF applications, and sadly, without a clear solution: Taking screenshot of a partially hidden window in a programmatic way
Is there a way to get a "clean" screenshot, may be with the use of the windows AutomationElement instance?

WebBrowser Control causes whole application to become unresponsive

I have a C# .NET 3.5 application with an embedded web browser. The browser is designed to point to remote sites (Rather than anything local). Everything works fine, but when the page is slow to respond this causes my entire application to become unresponsive until the page is loaded.
I don't mind the browser being unresponsive while it does its thing, but the application going too is far from ideal.
Is there a good way to prevent this? Would it be beneficial to run the WebBrowser on a seperate thread - that's a bit beyond my skillset right now and I don't think the WebBrowser control really likes multithreading? But I can learn if needs be.
See the answer #2 on this question for a solution on how to run it on a separate thread: BackgroundWorker and WebBrowser Control
You might as well read answer #1 too, it explain the behaviors you are seeing (WebBrowser control blocking UI thead).
As it happens I found that the root cause of this was my application running as administrator. Exactly the same issue was seen when using Internet Explorer - as such, I've simply rewritten the bits that required admin privileges so I'm now no longer seeing the original issue.
this happened only on win7;I use fiddler2 to Monitor HTTP/HTTPs traffic .I find embedded web browser to visit this web:http://ctldl.windowsupdate.com/msdownload/update/v3/static/trustedr/en/disallowedcertstl.cab?50ff94e72ac1a75c;the solution is follow:http://support.microsoft.com/kb/2730040/en (Method 2 or Method 3).you can try it.other u can use .net framework4.0,then u haven't this problem.

Allowing a WPF browser application to navigate to a separate web page when finished?

I have a WPF browser application that collects user data and adds it to a database to tell them when their software is out of date.
All of that works fine, but the problem is when the application finishes its stuff, I want the web page itself to change (i.e., detect the web app has hit a 'finished' state, then autonagivate to a results page or something).
I can't think of a way to accomplish this, since the web app itself doesn't seem to be able to change the IFRAME it's contained in, much less the page outside of that, or signal to javascript or anything.
Any ideas?
I'd make an variable to keep progress/step of work. And a timer which would check if progress=="done" or sth.
Maybe this is not the best way of solving this but I don't know WPF much and that solution first came to mind

How to put WebBrowser object into ASP.NET page

Hey guys, here's a unique problem I have to solve: I have a program which opens up a webpage through a WebBrowser object in c#, and does a bunch of operations with it. Now I need to integrate this functionality into my own webpage.
That means that either I need to take the c# code, and somehow make it work in my webpage itself (put in a WebBrowser object, set up event handlers, etc), or I need to somehow have my webpage open this program on my server, fire an event to start, and receive input from it. It is very important for me to use a WebBrowser object (or even WebKit.Net) because there is a lot of javascript, etc on the page that needs to be processed.
Any ideas on how to pull this off?
I expect that you'll have a problem running a Windows Forms control inside a process that has no Windows message pump. I don't think this will work directly within an ASP.NET site.
On the other hand, you can place the control and the code to manipulate it into a Windows Forms application, which can then host a WCF service. The ASP.NET application can request that the Windows Forms application do the manipulation of the control on its behalf.
Of course, you'll need to handle concurrency and state issues. If there are two requests from two different users at the same time, then you'll probably want separate instances of the WebBrowser control to handle them. If request 2 depends on what happened during request 1, then you've got state issues, and you'll need request 2 to use the same WebBrowser instance that was used for request 1.
This does not sound like fun. Instead, it sounds like an attempt to use a desktop design in a web application - that typically fails.

Spawning form in new process

I had originally created a windows form to be a dialog of my projects main form. Now the dialog is getting complex enough that it needs to be started in its own process. Is there a way to do this in code or do i need to create a new project and link my files to it?
I question the premise here - there is no reason to necessarily start a new "form" in a separate process. If the form is getting that complex, however, I would recommend simplifying it, if for no reason other than usability.
That being said, you can always launch a new process via Process.Start in code. If you want it to be in the same project, but start a separate process, you could launch the executing exe with a command line argument that allows you to switch which "form" is loaded at startup.
You will need to set up a communication layer (WCF using named pipes would probably be the best way to go).
But I would seriously question why you need a new process for your form? Make sure that whatever work you do on your form is done on a separate thread. That way you can have dozens of forms open but your app will remain very responsive.
It's not the best solution, but if you are trying to avoid a rewrite, a call to Application.DoEvents will pump the message queue and get you some responsiveness back if you have a whole lot of updates happening on your UI. Band aid solution to your problem though.

Categories

Resources