Use csharp sdk in console application
Hi,
i'm tryng to use csharp sdk in a console application, using the sample code to initialize and manage rainbow.application() class of the InstantMessage sample.
After login command I create a loop to check the until IsConnected() is true, but the connectionstatechanged is fired only with the 'connecting' event, and the login callback function it's not fired.
I've check the response from the server and the resoult is connected.
There are some restriction to use this sdk in console application ?
Regards,
Flavio
-
Hi,
The Rainbow CSharp SDK has been built to be asynchronous.
You can still create a console application but it's up to you to "synchronize" methods/API you want to use.
For example, the method "GetContactFromContactIdFromServer" can by used synchronous in this way:
public Contact GetContactFromContactIdFromServerSync(String contactId)
{
Contact contact = null;ManualResetEvent pause = new ManualResetEvent(false);
GetContactFromContactIdFromServer(contactId, callback =>
{
if (callback.Result.Success)
contact = callback.Data;pause.Set();
});
pause.WaitOne(2000); // <= In case of network trouble, we need also a Timer. Here 2 seconds
return contact;
}For the Login step, it's a little bit more complex since you need to wait 2 events: ConnectionStateChanged and InitializationPerformed. but it's still possible
Regards,
Christophe
Vous devez vous connecter pour laisser un commentaire.
Commentaires
2 commentaires