Загрузка...

Reopening the app

Thread in C# created by Renzo_inactive3269249 May 18, 2020. 160 views

  1. Renzo_inactive3269249
    Renzo_inactive3269249 Topic starter May 18, 2020 0 May 18, 2020
    Привет, сегодня я покажу тебе код, который не позволит пользователю открыть приложение второй раз. Собственно код в двух строках:
    Code
    var mutex = new Mutex(false, "97c91428a4034fe2a220cla44a95ef2b", out var cretedNew);
    if (!cretedNew)
    {
    Environment.Exit(0);
    }
     
  2. r3xq1
    r3xq1 May 18, 2020 53 Jul 27, 2018
    Лучше будет так:
    Code
    public static string GetGUID()
    {
    string result;
    try
    {
    Assembly assembly = typeof(Program).Assembly;
    var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
    result = attribute.Value;
    }
    catch { result = "CF2D4313-33DE-489D-9721-6AFF69841DEY"; }
    return result?.ToUpper();
    }
    public static bool Inizialize()
    {
    var app = new Mutex(true, GetGUID(), out bool isNew);
    GC.KeepAlive(app);
    return isNew;
    }
     
    1. Renzo_inactive3269249 Topic starter
      r3xq1, ммм у меня проще, и все отлично работает
    2. AlinGod
    3. Renzo_inactive3269249 Topic starter
      AlinGod, чем этот код отличается от моего? Включи мозги метод GetGUID в любом случае возвратит
      97c91428a4034fe2a220cla44a95ef2b, разницы нет.
Top
Loading...