Prevent multiple instances in server same username

前端 未结 2 1899
误落风尘
误落风尘 2021-01-18 22:13

I developed an application that is hosted in one server. Many users access to it via Remote Desktop connection, but sometimes I saw in the task manager that the same user ha

2条回答
  •  迷失自我
    2021-01-18 22:58

    You can create a mutex with the user's name.

    bool b = true;
    Mutex mutex = new Mutex(true, Environment.UserName.ToLowerInvariant() , out b);
    if (!b) throw new InvalidOperationException("Another instance is running");
    

提交回复
热议问题