private void UpdateTimeline()
        {
            lock (_lock)
            {
                while (true)
                {
                    WPost[] posts = new WPost[0];
                    Popups.UILoading loading = null;

                    if (_first == 0)
                    {
                        this.Dispatcher.BeginInvoke(new Action(delegate()
                        {
                            loading = new Popups.UILoading("Downloading posts");
                            UIController.ShowPanel(loading);
                        }));
                    }

                    switch (_timelineType)
                    {
                        case TimelineType.HomeTimeline:
                            posts = UIController.Proxy.GetHomeTimeline(UIController.MyProfile.Username, UIController.Password, _first);
                            break;
                        case TimelineType.PersonalTimeline:
                            posts = UIController.Proxy.GetUserTimeline(UIController.MyProfile.Username, UIController.Password, _owner.Username, _first);
                            break;
                        case TimelineType.DynamicTimeline:
                            posts = UIController.Proxy.GetIterationTimeline(UIController.MyProfile.Username, UIController.Password, _first);
                            break;
                        case TimelineType.InteractiveNetworkTimeline:
                            if (UIController.GetCurrentCollectionURL() != null)
                            {
                                Tuple<string, string> tempObject = UIController.GetActiveObject();
                                if (tempObject != null)
                                {
                                    if (tempObject.Item1 != _interactiveObject.Item1 || tempObject.Item2 != _interactiveObject.Item2)
                                    {
                                        _first = 0;
                                        _last = 0;
                                        this.Dispatcher.BeginInvoke(new Action(delegate()
                                            {
                                                UIController.HidePanel(loading);
                                                TimelineStackPanel.Children.Clear();
                                                loading = new Popups.UILoading("Downloading posts");
                                                UIController.ShowPanel(loading);
                                            }));
                                        _interactiveObject = tempObject;
                                    }
                                    posts = UIController.Proxy.GetInteractiveTimeline(UIController.MyProfile.Username, UIController.Password, UIController.GetCurrentCollectionURL(), _interactiveObject.Item1, _interactiveObject.Item2, _first);

                                    // Reload timeline if document change during posts download
                                    tempObject = UIController.GetActiveObject();
                                    if (tempObject.Item1 != _interactiveObject.Item1 || tempObject.Item2 != _interactiveObject.Item2)
                                    {
                                        this.Dispatcher.BeginInvoke(new Action(delegate()
                                            {
                                                UIController.HidePanel(loading);
                                            }));
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                _first = 0;
                                _last = 0;
                                this.Dispatcher.BeginInvoke(new Action(delegate()
                                {
                                    //TODO Displays a message informing the user that needs to connect to a TFS collection
                                    TimelineStackPanel.Children.Clear();
                                }));
                            }
                            break;
                    }

                    this.Dispatcher.BeginInvoke(new Action(delegate()
                    {
                        if (posts.Length > 0)
                        {
                            _first = posts.First().Id;
                            if (_last == 0)
                                _last = posts.Last().Id;
                            for (int i = 0; i < posts.Length; i++)
                                if (_timelineType == TimelineType.PersonalTimeline)
                                    TimelineStackPanel.Children.Insert(i, new UIPost(posts[i], false));
                                else
                                    TimelineStackPanel.Children.Insert(i, new UIPost(posts[i], true));
                        }

                        UIController.HidePanel(loading);
                    }));

                    Monitor.Wait(_lock, new TimeSpan(0, 1, 0));
                }
            }
        }
        private void downloadOlderPosts()
        {
            WPost[] posts = new WPost[0];

            switch (_timelineType)
            {
                case TimelineType.HomeTimeline:
                    posts = UIController.Proxy.GetHomeTimeline(
                        UIController.MyProfile.Username, UIController.Password, 0, _last);
                    break;
                case TimelineType.PersonalTimeline:
                    posts = UIController.Proxy.GetUserTimeline(
                        UIController.MyProfile.Username, UIController.Password, _owner.Username, 0, _last);
                    break;
                case TimelineType.DynamicTimeline:
                    posts = UIController.Proxy.GetIterationTimeline(
                        UIController.MyProfile.Username, UIController.Password, 0, _last);
                    break;
                case TimelineType.InteractiveNetworkTimeline:
                    posts = UIController.Proxy.GetInteractiveTimeline(
                        UIController.MyProfile.Username, UIController.Password, UIController.GetCurrentCollectionURL(),
                        _interactiveObject.Item1, _interactiveObject.Item2, 0, _last);
                    break;
            }

            this.Dispatcher.BeginInvoke(new Action(delegate()
            {
                Busy.Visibility = Visibility.Hidden;
                if (posts.Length > 0)
                {
                    _last = posts.Last().Id;
                    foreach (WPost p in posts)
                        if (_timelineType == TimelineType.PersonalTimeline)
                            TimelineStackPanel.Children.Add(new UIPost(p, false));
                        else
                            TimelineStackPanel.Children.Add(new UIPost(p, true));
                    LoadingText.Visibility = Visibility.Hidden;
                }
                else
                {
                    LoadingText.Visibility = Visibility.Visible;
                    LoadingText.Text = "There are no older posts";
                }
                _olderPostAllowed = true;
            }));
        }