Reputation: 95
I have a form with a timer on it. On timer Tick Event I have the following code:
private void timer1_Tick(...) {
Process.Start("http://www.google.com");
}
I want whenever the tick event is fired, the webpage will open only if it wasn't already open.
Upvotes: 0
Views: 194
Reputation: 17366
This is not an answer to your question but a suggestion to try a different approach.
You can try putting the WebBrowser
control on a form (Winform) instead of launching a new browser window. This way you'd have complete control over when and what link to open instead of trying to figure out from the system (and from the various browsers) if a given web page is already open. The WebBrowser
control gives you a fair amount of control over the properties / events of the underlying browser window so you'd likely have an easier time doing what you're trying to do.
You'd have to add your own address bar / toolbar (if you need any of these) but that's still a lot less work doing it that way. There are certain things that you cannot do using WebBrowser
but they'd be next to impossible to do using your current approach anyway.
To give an actual (incomplete) answer to your question: it's possible to achieve what you're trying to do but it's fairly tricky and not completely reliable. Personally I wouldn't waste time with it.
Edit: as SpikeX recommended in a comment, you can also use Awesomium as an embedded browser. I didn't know about it before.
Upvotes: 2
Reputation: 412
If you want some process to be fired only one time don't use a timer for this. Call the process inside your Mainwindow constructor, the Loaded event of the window, or inside a click event of a button. Another way is to use a counter, and in the tick method to increment it. All you have to do is to stop the timer if this counter equals 1, by writing Timer.Stop();
Upvotes: 0