Condition false, but code inside the if statement executed

前端 未结 3 1863
醉梦人生
醉梦人生 2020-12-19 22:55

I have the following method:

public bool ConnectAsync()
{
    if (IsConnected)
        throw new InvalidOperationException(\"Socket is already connected\");
         


        
3条回答
  •  既然无缘
    2020-12-19 23:24

    This is probably an issue with the debugger and multiple threads, try putting the lock around the outside of the if statement rather than inside the property.

提交回复
热议问题