So I’ve been posting this week for help with an API that has asynchronous calls. You can view the CODE here: C# asynchronous event procedure does not fire
With a little more digging, I found out that the API is written in VB.NET and I created a VB.NET example and guess what . . . the asynchronous calls work like a charm.
So, now I need to find out why the calls are not firing in the C# code I have. The API being written in VB really shouldn’t matter, but again, the VB.NET code works and my C# does not. Is there a problem with the event handler and hows its being declared that causes it to not fire?
UPDATE VB Code added
Imports ClientSocketServices
Imports DHS_Commands
Imports DHS
Imports Utility
Imports SocketServices
Class Window1
Public WithEvents AppServer As New ClientAppServer
Public Token As LoginToken
Private Sub login()
Dim handler As New LoginHandler
Token = handler.RequestLogin("admin", "admin", localPort:=12000, serverAddress:="127.0.0.1", serverLoginPort:=11000, clienttype:=LoginToken.eClientType.Client_Admin, timeoutInSeconds:=20)
If Token.Authenticated Then
AppServer = New ClientAppServer(Token, True)
AppServer.RetrieveCollection(GetType(Gateways))
End If
End Sub
Private Sub ReceiveMessage(ByVal rr As RemoteRequest) Handles AppServer.ReceiveRequest
If TypeOf (rr.TransferObject) Is Gateways Then
MsgBox("dd")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
login()
End Sub
End Class
You’re VB code is quite different from your c# code.
Try converting your vb code to c#, but keep in mind that you don’t get WithEvents, so any time you
AppServer = New ClientAppServer(Token, True);you will need to
AppServer.ReceiveRequest += ReceiveMessage;EDIT: I converted your code using http://www.developerfusion.com/tools/convert/vb-to-csharp/ I also editted it by hand to make the events work. Keep in mind that I haven’t tested this; I apologize for any typos/etc.
I’m also wondering, is your button click actually happening? Where is the event handler added check that it actually is in your IntializeComponent?