문제

I have a program on a remote server that I access via remote desktop and I was wondering if there is any way to restrict the program to be used by one user at a given moment?

For instance while user A is using the program, I want to prevent users B,C,etc.. from running it.

도움이 되었습니까?

해결책

Check out this answer

.NET Check if another application is running

Here is an example of one approach (VB.NET):

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    If (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1) Then Close()
End Sub

Though in researching this, it seems that using a Mutex is a better approach, albeit a much more complicated one, because it's possible that, using the simple approach exemplified above, you could run into trouble if more than one of your processes has the same name. This seems to be one of the definitive q&a's on the topic:

What is a good pattern for using a Global Mutex in C#?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top