/// <summary>
 /// Logs into the MessengR service using forms auth and retrives an auth cookie.
 /// </summary>
 public static Task<AuthenticationResult> LoginAsync(string url, string userName, string password)
 {
     HubConnection connection = new HubConnection(url) { CookieContainer = new CookieContainer() }; ;
     TaskHub taskHub = new TaskHub(connection);
     var tcs = new TaskCompletionSource<AuthenticationResult>();
     connection.Start().ContinueWith(task =>
      {
       taskHub.Logon(userName, password).ContinueWith(logon => 
           taskHub.LogonStatus += logonStatus => tcs.SetResult(new AuthenticationResult
                                                                   {
                                                                       Status = logonStatus.Status
                                                                   }));
      });
     
     return tcs.Task;
 }
        private void InitializeConnection(string url)
        {
            _connection = new HubConnection(url) { CookieContainer = new CookieContainer() };

            // Get a reference to the chat proxy
            taskHub = new TaskHub(_connection);

            this.Conversations = new ObservableCollection<Message>();
            
            

            taskHub.Message += (message,id) =>
                {
                    this._syncContext.Post(
                        state =>
                            {
                                this.Conversations.Add(new Message { Value = message.Description});
                            },
                        null);
                    
                };

            // Start the connection
            _connection.Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    // Show a connection error here
                }
                else
                {
                    taskHub.Join(2, Name);
                }

            });

            // Fire events on the ui thread
            taskHub.Message += (message,projId) => _syncContext.Post(x => OnMessage(message,projId), null);
        }