Method calling not working?

  • Thread starter Thread starter Tales Normando
  • Start date Start date
T

Tales Normando

Hi,

Elighten me what's wrong, please.
I'm working on a project that uses 2 programs, a client and a
server. The server must remote a message exchange class to provide
communication between both. At some point on the Main sub this code is
called:
Dim Tcp As TcpChannel = New TcpChannel(3781)
ChannelServices.RegisterChannel(Tcp)

RemotingConfiguration.RegisterWellKnownServiceType(GetType(Messenger),
"Messaging", WellKnownObjectMode.SingleCall)
MessageListener = New Thread(AddressOf ProcessMessages)
MessageListener.Start()

Sometime later, the ProcessMessages is then called:
Private Sub ProcessMessages()

Dim ServerMessages As Messenger =
Activator.GetObject(GetType(Messenger), "tcp://localhost:3781/Messaging")
ServerMessages.RegisterHandle(System.Net.Dns.GetHostName())

Try

Do While True

Do While Not ServerMessages.HasMessages

Thread.Sleep(1000)

Loop

...

End Try

End Sub

The problem is when I call ServerMessages.HasMessages I get an
ArgumentNullException: key cannot be null; which is strange, considering the
Messenger class code:
Private InstanceHandle As IComparable
Private Shared MessageQueues As Hashtable

Public Sub RegisterHandle(ByVal Handle As IComparable)

If InstanceHandle Is Nothing Then

If Not MessageQueues.ContainsKey(Handle) Then

InstanceHandle = Handle
MessageQueues.Add(Handle, New Queue())

Else

Throw New ApplicationException()

End If

Else

Throw New ApplicationException()

End If

End Sub

Public ReadOnly Property HasMessages() As Boolean
Get

Dim MessageQueue As Queue = MessageQueues(InstanceHandle)
HasMessages = (MessageQueue.Count > 0)

End Get
End Property

Worse, if I change the variable ServerMessage's definition so
that it is a local variable instead of a remoted one, the code works fine.
What the hell is wrong?


Tales Normando
 
I've just realized that I could create the ServerMessages variable locally
with the New operator and the MessageQueues variable would still be the same
used by the clients, but I still wish to hear why this code's not working
because it will be almose the same on the client side, where I certainly
CANNOT create it with New.
 
Never mind that, I've figured it out.

Tales Normando said:
Hi,

Elighten me what's wrong, please.
I'm working on a project that uses 2 programs, a client and a
server. The server must remote a message exchange class to provide
communication between both. At some point on the Main sub this code is
called:

"Messaging", WellKnownObjectMode.SingleCall)

Sometime later, the ProcessMessages is then called:

Activator.GetObject(GetType(Messenger), "tcp://localhost:3781/Messaging")

The problem is when I call ServerMessages.HasMessages I get an
ArgumentNullException: key cannot be null; which is strange, considering the
Messenger class code:


Worse, if I change the variable ServerMessage's definition so
that it is a local variable instead of a remoted one, the code works fine.
What the hell is wrong?


Tales Normando
 
Back
Top