I need call another method when awaited ConnectAsync method finish. I try thread pool, cycles etc but I still have the same problem because when start method ConnectAsync then is immediately calling next method but I need first finish ConnectAsync method then call my method. Method ConnectAsync is connecting to server in my web socket client and when Im connected then my method should be called(method navigate to another page). Any idea? .
Awaited method: await socket.ConnectAsync(server)
My method which I want call when awaited finish: Frame.Navigate(typeof(MainContentPage));
Method in my web socket client:
public async void _connect(string token, string idInstalation, string lang)
{
try
{
if (token!=null){
socket.SetRequestHeader("Token", token);
socket.SetRequestHeader("Lang", lang);
socket.SetRequestHeader("idInstallation", idInstalation);
}
await socket.ConnectAsync(server);
System.Diagnostics.Debug.WriteLine("Connected");
connected = true;
writer = new DataWriter(socket.OutputStream);
messageNumber = 1;
}
catch (Exception)
{
var dialog = new MessageDialog("Cannot connect to server", "Error").ShowAsync();
}
}
public static void connect(string token, string idInstalation, string lang)
{
instance._connect(token,idInstalation,lang);
}
Mainpage where is calling websocket method:
private void connectMe()
{
WebSocketClient.connect(null, null, null);
Frame.Navigate(typeof(MainContentPage));
}