You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In class QCallbackConnection a lock is performed on the instance object (this). This is usually considered a defect as it can leads to deadlock in some cases.
From Microsoft's documentation:
In general, avoid locking on a public type, or instances beyond your code's control. The common constructs lock (this), lock (typeof (MyType)), and lock ("myLock") violate this guideline:
lock (this) is a problem if the instance can be accessed publicly.
lock (typeof (MyType)) is a problem if MyType is publicly accessible.
lock("myLock") is a problem because any other code in the process using the same string, will share the same lock.
Best practice is to define a private object to lock on, or a private static object variable to protect data common to all instances.
Since the StartListener() and StopListener() methods are virtual, the best way would be to have a private object to hold the lock, make both methods non-virtual and provide two overridable protected methods, such as:
In class
QCallbackConnection
a lock is performed on the instance object (this
). This is usually considered a defect as it can leads to deadlock in some cases.From Microsoft's documentation:
Since the
StartListener()
andStopListener()
methods are virtual, the best way would be to have a private object to hold the lock, make both methods non-virtual and provide two overridable protected methods, such as:References:
The text was updated successfully, but these errors were encountered: