Sunday, November 15, 2009 12:49 PM
Make your site run only in ONE Browser window(single instance)!
While a was at Teched2009 and watching Tim Heuer presenting Silverlight 3 I noticed a new cool feature named Local Messaging!
When I saw this new feature, a crazy idea crossed my mind. Could this be used in order to allow the user to open my website in only one browser window?
The answer is yes! But not the way I first thought. Here is how (code in MainPage.xaml.cs):
string _localName = "SL App";
bool _Close = false;
Loaded += new RoutedEventHandler(MainPage_Loaded);
LocalMessageReceiver incomingMessage = new LocalMessageReceiver(_localName);
_Close = true;
protected void MainPage_Loaded(object sender, RoutedEventArgs e)
LocalMessageSender msgSender = new LocalMessageSender(_localName);
msgSender.SendAsync("New instance loaded");
Clicking on the first link
Then on the second link
Those are the files in the solution
That’s an exception driven solution but works for me! :)
This works also across different browsers but if you want you can changed to allow one instance per browser.
Here are the solution files.
Filed under: Web Development, ASP.NET, C#, Silverlight