views:

29

answers:

2

Hi

I have already opened a webpage in Firefox which is actually running through the apache web server on the same machine. And I have C# application running on the same machine. Now I want to refresh/inform my already open web page that C# has finished processing. I have seen the threads all over the web and also some similar threads on Stackoverflow but did not find solution.

Any idea how to solve this?

In details: C# Application is transferring images from external storage. Web page (http://127.0.0.1/mypage.php) is looking for the images periodically, but never know that all images are transferred or not so that it can process these images to do some more work. In this scenario, we want to tell our web page (which is already running in firefox) all data transferred and now you can refresh to process data.

A: 

You can include a Internet Explorer control in ouyr appliacation. This way you can control which page is displayed and you can call refresh and whatever you want.

Another way is to include a meta refresh tag in the html page so it periodically looks for updates and refreshes ifself.

I see no way to remote control firefox. The only thing i could think of is remember the process id when you start firefox, and the you kill the process and start a new window, but I consider this bad style.

codymanix
I thought of killing browser and opening again, but I thought as you that its a bad approach
ZHS
+1  A: 

Two steps: Let the server communicate that C# is done, and have the web page react to it

You somehow need to expose the fact that the C# program has finished to the web. If you also have an IIS running, this could be done via a URL served by IIS directly that returns a value indicating whether C# is still running or not. If you don't, you can write to a file, database or whatever and have a script on your Apache server that checks for this value. Whatever you choose, you want something like www.myserver.com/are_you_finished.[php, aspx, whatever] that returns 1 or 0

Then, you can build JavaScript script in your client page that periodically checks this URL and reacts as soon as the value is 1. This would be a typical AJAX call, ie you need to play with XmlHttpRequest. This could be elaborated much further, but maybe you first say if that's what you have in mind, and I also think there's a lot of good documentation on how to do this on here.

Nicolas78
upon reading your question again, it occurs to me that you may have browser, apache and C# all running on the same machine. well that's not a problem, the solution I've proposed runs in this case as well, it just generalizes to situations where the browser runs on a remote machine. There may be other approaches specific to the single-computer situation, but I don't think they'd ever get particularly pretty ;)
Nicolas78
I have thought of generating a file or the same as you mentioned. But then I thought, what if C# application indicated that I am doing some work and web page checks it periodically. How to handle the situation if C# Application some how crashed and generated file still says that C# Application is still busy in process!
ZHS
ok that's a problem, but not related to the specific approach I describe. If the C# program was to actively notify another process, crashing the program would destroy such other approaches as well since the C# problem would never reach the point to tell the other application "I'm done". So basically you have to fine-tune the first part of the approach. One thing to do might be to see if images have been added in the last n seconds and to conclude that the application is done if not.
Nicolas78
alternatively, have the C# application write a file or database entry saying "I am busy" like once a second. As soon as the file or entry is older than one second, you know you're done or at least in some way the C# program has stopped working.
Nicolas78