only My site
Showing posts with label WPF. Show all posts
Showing posts with label WPF. Show all posts

Friday, February 25, 2011

WPF : Restrict Multiple Instance

protected override void OnStartup(StartupEventArgs e){

// Get Reference to the current Process

Process thisProc = Process.GetCurrentProcess();

// Check how many total processes have the same name as the current one

if (Process.GetProcessesByName(thisProc.ProcessName).Length > 1)

{

// If ther is more than one, then it is already running.

MessageBox.Show("Another Instance is already running.");

Application.Current.Shutdown();

return;

}

base.OnStartup(e);

}

Wednesday, January 5, 2011

using System.Drawing;
using System.Reflection;
using System.IO;

//Decleration
Assembly _assembly;
Stream _imageStream;


//Option 1
Uri iconUri = new Uri("pack://application:,,,/favicon.ico", UriKind.RelativeOrAbsolute);
this.Icon = BitmapFrame.Create(iconUri);

//Option 2
_assembly = Assembly.GetExecutingAssembly();
_imageStream = _assembly.GetManifestResourceStream("EdwardsMbt.ClientApp.favicon.ico");

this.Icon = BitmapFrame.Create(_imageStream);