Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
sealed class Program
{
[STAThread]
static void Main() {
MyForm app = null;
Mutex mutexObj = null;
bool mutexCreated = false;
try {
mutexObj = new Mutex( true, "MyApp only One-Instance Startupcheck", out mutexCreated );
Process proc = InstanceHandler.RunningInstance();
if ( proc != null || !mutexCreated ){
ErrorMessages.Show_OnlyOneProgInstance();
InstanceHandler.HandleRunningInstance( proc );
}
else{
Application.EnableVisualStyles();
Application.DoEvents();
app = new MyForm();
Application.Run( app );
}
}
catch ( Exception ex ) {
MessageBox.Show(
string.Format( "{0}{1}{1}{2}", ex.GetType().FullName, Environment.NewLine, ex.ToString() ),
string.Format( "{0} ({1})", ex.Source, ex.GetType().Name ) );
}
finally {
if ( app != null ) {
app.Dispose();
app = null;
}
if ( mutexObj != null ){
if ( mutexCreated )
mutexObj.ReleaseMutex();
mutexObj = null;
}
GC.WaitForPendingFinalizers();
GC.Collect();
}
}
}
public sealed class InstanceHandler
{
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
private const int WS_SHOWNORMAL = 1;
public InstanceHandler(){}
public static Process RunningInstance() {
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName( current.ProcessName );
foreach ( Process process in processes ){
if ( process.Id != current.Id ){
if ( System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("/", "\\") ==
process.MainModule.FileName ){
return process;
}
}
}
return null;
}
public static void HandleRunningInstance( Process instance ) {
if ( instance != null ){
ShowWindowAsync( instance.MainWindowHandle , WS_SHOWNORMAL );
SetForegroundWindow( instance.MainWindowHandle );
}
}
}