473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Method calling not working?

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.GetHo stName())

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
Nov 20 '05 #1
2 1189
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.

"Tales Normando" <ta*****@ibest.com.br> escreveu na mensagem
news:uv**************@TK2MSFTNGP12.phx.gbl...
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.GetHo stName())

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

Nov 20 '05 #2
Never mind that, I've figured it out.

"Tales Normando" <ta*****@ibest.com.br> escreveu na mensagem
news:uv**************@TK2MSFTNGP12.phx.gbl...
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.GetHo stName())

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

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Chris S. | last post by:
Is there a purpose for using trailing and leading double underscores for built-in method names? My impression was that underscores are supposed to imply some sort of pseudo-privatization, but would...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
2
by: Jon Shemitz | last post by:
I'm puzzled by this, code clarified from working code IToolboxService GetToolboxService(IDesignerHost AnyDesigner) { return (IToolboxService) AnyDesigner.RootComponent.Site. GetService(...
3
by: Daniel Diehl | last post by:
Good morning! Now I'm sitting over 2 hours on a problem calling a method in the logitech SDK DLL. Everything is working fine, but calling one method I fell in a problem. I'm not that old with C#...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
5
by: joeblast | last post by:
I have a Web service that gets the financial periods and hold a reference to a disconnected dataset built at initialization. Web methods work on the dataset inside the web service. Everything is...
2
by: BBM | last post by:
I may be putting too fine a point on this, but I'd like to be able to know the class name of a shared method from within the method. BTW, the shared method is in a "MustInherit" class. So it...
1
by: ravikumar2007 | last post by:
I am working with .NET 3.5 framework within an WPF application. I have a windows application where for a textbox, I have defined the lost focus event. I need to call the Focus() method of any other...
12
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I have a class which "BiologySequence" which looks about like this. public class BiologySequence { private string _Sequence; public string Sequence {
9
by: VK | last post by:
<OT>I am finishing TransModal 0.1 so planning to move it from alpha to beta stage.<OT> Besides that I am planning to write an introductory to inheritance schema currently used in Javascript...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.