Archive | February, 2012

Single Instanced OOB Silverlight Applications

22 Feb

Many followers asked me about silverlight application that has only one instance, after investigation of some hours i have found a simple solution.

Silverlight has a built in mechanism for communication of applications running on a same computer by taking advantage of this we have a work around thats work!

For both send and receive messages application have to register with unique name so ListenFailedException will occur if its going to register any application with same name again.

try
{
var receiver = new LocalMessageReceiver(“firstinstance”);
receiver.Listen();
this.RootVisual = new MainPage();
}
catch (ListenFailedException)
{
MessageBox.Show(“Application already running! Only one Instance can be run at a time”);
this.MainWindow.Close();
}

Will work for both in/out Browser, LocalMessageReceiver object can only be create only in OOB mode depend on need

Follow

Get every new post delivered to your Inbox.