1

I'm using xSockets to create a simple chat app on windows phone 8, but Im having the following problem, on run it says "does not contain definition for invoke method", I read somewhere that I have to use Dispatch, but also no luck.

My Code:

private async void Connect()
    {
        Connection = new XSocketClient(ServerURI, Origin, "chat");

        chatController = Connection.Controller("chat");

        //Handle incoming event from server: use Invoke to write to console from XSocket's thread
        chatController.On<string>("addMessage", message => this.Invoke((Action)(() =>
                       RichTextBoxConsole.Text =(String.Format("{0}" + Environment.NewLine, message))
                   )));

        try
        {
            Connection.Open();
            comboBoxLocation.SelectedIndex = 0;

            await chatController.SetProperty("username", UserName);
        }
        catch
        {
            StatusText.Text = "Unable to connect to server: Start server before connecting clients.";
            No connection: Don't enable Send button or show chat UI
            return;
        }
    }

1 Answers1

0

It looks like you just copied the sample for WinForms from XVA-07-03 into a WindowsPhone 8.1 project.

I added a WP 8.1 project to test and the code you need to make this work is this instead of your "Invoke" stuff

chatController.On<string>("addMessage", message => this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
    this.Messages.Text += String.Format("{0}" + Environment.NewLine, message);
})); 
Uffe
  • 2,275
  • 1
  • 13
  • 9