A
Andrew Baker
I have some code to ensure a singleton which has worked perfectly for years.
I need to alter it to work such that each user on TerminalServices gets
their own instance of the application (and therefore each form). Can
someone offer a good solution? (and yes, I have googled but nothing obvious
came up)
Private Shared somePrivateStaticObject As New Object 'used for threadsafty
and locking
Private Shared myInstance As frmControl
Public Shared Function GetInstance() As frmControl
SyncLock (somePrivateStaticObject) ' make it threadsafe
If myInstance Is Nothing Then
myInstance = New frmControl
End If
End SyncLock
Return myInstance
End Function
I was thinking of changing the lock object to something like
Dim somePrivateStaticObject As String = "formName" +
loggedInUserName
Private myInstance As frmControl
but that throws an error of: "Cannot refer to an instance member of a class
from within a shared method or shared member initializer without an explicit
instance of the class."
as I dont yet have a class and the object is no longer shared.
Can someone suggest a way that works??
Thanks
Andrew.
I need to alter it to work such that each user on TerminalServices gets
their own instance of the application (and therefore each form). Can
someone offer a good solution? (and yes, I have googled but nothing obvious
came up)
Private Shared somePrivateStaticObject As New Object 'used for threadsafty
and locking
Private Shared myInstance As frmControl
Public Shared Function GetInstance() As frmControl
SyncLock (somePrivateStaticObject) ' make it threadsafe
If myInstance Is Nothing Then
myInstance = New frmControl
End If
End SyncLock
Return myInstance
End Function
I was thinking of changing the lock object to something like
Dim somePrivateStaticObject As String = "formName" +
loggedInUserName
Private myInstance As frmControl
but that throws an error of: "Cannot refer to an instance member of a class
from within a shared method or shared member initializer without an explicit
instance of the class."
as I dont yet have a class and the object is no longer shared.
Can someone suggest a way that works??
Thanks
Andrew.