Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WP7中拒绝每次更新/刷新列表框?_C#_Silverlight_Windows Phone 7_Listbox - Fatal编程技术网

C# 如何在WP7中拒绝每次更新/刷新列表框?

C# 如何在WP7中拒绝每次更新/刷新列表框?,c#,silverlight,windows-phone-7,listbox,C#,Silverlight,Windows Phone 7,Listbox,我有一个列表框,里面有大约40-150个项目。当我点击更新按钮时,我的应用程序会在后台线程中检查新的新闻和消息。如果有消息或新闻更新,应用程序将显示通知。即使没有新的新闻或消息项,“我的列表框”也会刷新,并且在1-10秒内仍然没有响应。在这种情况下,如何禁用更新? 我的代码很清楚,这个线程在后台工作。我也有 private void UpdateNews(对象发送方,事件参数e){ 调度程序计时器=新调度程序(){ }; 计时器。勾选+=(a,b)=>{ timer.Stop(); getDat

我有一个列表框,里面有大约40-150个项目。当我点击更新按钮时,我的应用程序会在后台线程中检查新的新闻和消息。如果有消息或新闻更新,应用程序将显示通知。即使没有新的新闻或消息项,“我的列表框”也会刷新,并且在1-10秒内仍然没有响应。在这种情况下,如何禁用更新? 我的代码很清楚,这个线程在后台工作。我也有

private void UpdateNews(对象发送方,事件参数e){
调度程序计时器=新调度程序(){
};
计时器。勾选+=(a,b)=>{
timer.Stop();
getData(“后期upd”);
};
timer.Start();
ProgBar.IsIndeterminate=真;
ProgBar.Visibility=System.Windows.Visibility.Visible;
}
公共void getData(字符串过滤器){
锁(这个){
WriteLine(“新闻:获取数据”);
WebClient c=新的WebClient();
WebClient b=新的WebClient();
DateTime from=DateTime.Now.AddHours(-30);
如果(过滤器==“post”){
b、 下载StringAsync(新Uri(“https://api.vkontakte.ru/method/getServerTime?access_token=“+((App)Application.Current.access_token));
b、 DownloadStringCompleted+=新的DownloadStringCompletedEventHandler(服务器\u时间\u更新);
}
如果(过滤器==“安装后”){
调度程序计时器=新调度程序(){
};
计时器.勾号+=(a,q)=>{
timer.Stop();
b、 下载StringAsync(新Uri(“https://api.vkontakte.ru/method/getServerTime?access_token=“+((App)Application.Current.access_token));
b、 DownloadStringCompleted+=新的DownloadStringCompletedEventHandler(服务器\u时间\u更新);
c、 下载StringAsync(新Uri(“https://api.vkontakte.ru/method/newsfeed.get?start_time=“+((App)Application.Current.server_time+”&filters=post“+”&access_-token=“+((App)Application.Current.access_-token));
c、 DownloadStringCompleted+=新的DownloadStringCompletedEventHandler(posts\U更新);
newslistBox.PullSubtext=“бббббббббббббббб;
};
timer.Start();
}
}
服务器更新后的私有无效(字符串过滤器){
WebClient c=新的WebClient();
c、 DownloadStringAsync(新Uri(“…?start_time=“+((App)Application.Current).server_time-8600)+”和filters=“+filter+”&access_-token=“+((App)Application.Current).access_-token));
c、 DownloadStringCompleted+=新的DownloadStringCompletedEventHandler(已下载的帖子);
newslistBox.PullSubtext=“бббббббббббббббб;
}
私有void posts_已下载(对象发送方,下载StringCompletedEventArgs e){
if(e.Error==null&&(NetworkInterface.GetIsNetworkAvailable()){
锁(这个){
Debug.WriteLine(“新闻:在线下载帖子”);
字符串json=e.Result;
var response=JObject.Parse(json);
//Debug.WriteLine(响应);
字符串att_type=“”;
列表=新列表();
prof_list=新列表();
组列表=新列表();
配置文件p_项=空;
组g_项=空;
#区域交换
开关(附件式){
案例“照片”:。。。
打破
案例“涂鸦”:。。。
列表。添加(项目);
打破
案例“音频”:。。。
};
列表。添加(项目);
打破
案例“链接”:…};
列表。添加(项目);
打破
案例“注”:
item=新数据{。。。
列表。添加(项目);
打破
案例“帖子”:。。。
列表。添加(项目);
打破
“投票”一案:
item=新数据{。。。。
列表。添加(项目);
打破
案例“视频”:。。。。
列表。添加(项目);
打破
}
#端区
}
this.newslistBox.ItemsSource=list;
ProgBar.IsIndeterminate=false;
ProgBar.Visibility=Visibility.Collapsed;
}
}否则{
ToastPrompt toast=新的ToastPrompt();
//Debug.WriteLine(who.ToString());
//Debug.WriteLine(who.FirstOrDefault()[4].ToString());
toast.TextOrientation=System.Windows.Controls.Orientation.Vertical;
toast.Title=“ббба”;
toast.Message=“ццццццццццццццц109;
toast.millissecondSunTilHidden=7000;
toast.Show();
}
}
私有void posts\u更新(对象发送方,下载StringCompletedEventArgs e){
if(e.Error==null&&(NetworkInterface.GetIsNetworkAvailable()){
private void UpdateNews(object sender, EventArgs e) {
            DispatcherTimer timer = new DispatcherTimer() {
            };
            timer.Tick += (a, b) => {
                timer.Stop();
                getData("post_upd");
                };
            timer.Start();
            ProgBar.IsIndeterminate = true;
            ProgBar.Visibility = System.Windows.Visibility.Visible;
        }

public void getData(string filtr) {
            lock (this) {

                    Debug.WriteLine("News: Getting Data");
                    WebClient c = new WebClient();
                    WebClient b = new WebClient();
                    DateTime from = DateTime.Now.AddHours(-30);

                    if (filtr == "post") {

                        b.DownloadStringAsync(new Uri("https://api.vkontakte.ru/method/getServerTime?access_token=" + ((App)Application.Current).access_token));
                        b.DownloadStringCompleted += new DownloadStringCompletedEventHandler(server_time_update);


                    }
                    if (filtr == "post_upd") {
                        DispatcherTimer timer = new DispatcherTimer() {
                        };
                        timer.Tick += (a, q) => {
                            timer.Stop();
                            b.DownloadStringAsync(new Uri("https://api.vkontakte.ru/method/getServerTime?access_token=" + ((App)Application.Current).access_token));
                            b.DownloadStringCompleted += new DownloadStringCompletedEventHandler(server_time_update);
                            c.DownloadStringAsync(new Uri("https://api.vkontakte.ru/method/newsfeed.get?start_time=" + ((App)Application.Current).server_time + "&filters=post" + "&access_token=" + ((App)Application.Current).access_token));
                            c.DownloadStringCompleted += new DownloadStringCompletedEventHandler(posts_update);
                            newslistBox.PullSubtext = "Обновлено в " + DateTime.Now.ToString("HH:mm:ss");
                        };
                        timer.Start();

                    }
            }

private void after_server_time_update(string filtr) {
            WebClient c = new WebClient();
            c.DownloadStringAsync(new Uri("...?start_time=" + (((App)Application.Current).server_time - 8600) + "&filters=" + filtr + "&access_token=" + ((App)Application.Current).access_token));
            c.DownloadStringCompleted += new DownloadStringCompletedEventHandler(posts_downloaded);
            newslistBox.PullSubtext = "Обновлено в " + DateTime.Now.ToString("HH:mm:ss");
        }
  private void posts_downloaded(object sender, DownloadStringCompletedEventArgs e) {
            if (e.Error == null && (NetworkInterface.GetIsNetworkAvailable())) {
                lock (this) {
                    Debug.WriteLine("News: Posts Downloaded online");
                    string json = e.Result;
                    var response = JObject.Parse(json);
                    // Debug.WriteLine(response);
                    string att_type = "";
                    list = new List<Data>();
                    prof_list = new List<Profiles>();
                    groups_list = new List<Groups>();
                    Profiles p_item = null;
                    Groups g_item = null;
                        #region SWTICH
                        switch (att_type) {
                            case "photo":...
                                break;
                            case "graffiti":...
                                list.Add(item);
                                break;
                            case "audio":...
                                };
                                list.Add(item);
                                break;
                            case "link":...};
                                list.Add(item);
                                break;
                            case "note":
                                item = new Data {...
                                list.Add(item);
                                break;
                            case "post":...
                                list.Add(item);
                                break;
                            case "poll":
                                item = new Data {....
                                list.Add(item);
                                break;
                            case "video":....
                                list.Add(item);
                                break;
                        }
                        #endregion
                    }
                    this.newslistBox.ItemsSource = list;

                    ProgBar.IsIndeterminate = false;
                    ProgBar.Visibility = Visibility.Collapsed;
                }
            } else {
                ToastPrompt toast = new ToastPrompt();
                // Debug.WriteLine(who.ToString());
                //  Debug.WriteLine(who.FirstOrDefault()[4].ToString());
                toast.TextOrientation = System.Windows.Controls.Orientation.Vertical;
                toast.Title = "Ошибка";
                toast.Message = "Нет соединения с интернетом";
                toast.MillisecondsUntilHidden = 7000;
                toast.Show();
            }
        }
        private void posts_update(object sender, DownloadStringCompletedEventArgs e) {
            if (e.Error == null && (NetworkInterface.GetIsNetworkAvailable())) {
                lock (this) {
                    Debug.WriteLine("News: Posts Updated online");
                    string json = e.Result;
                    var response = JObject.Parse(json);
                    if (response["response"]["items"].HasValues) {
                        // Debug.WriteLine(response);
                        string att_type = "";
                        //list = new List<Data>();
                        prof_list = new List<Profiles>();
                        groups_list = new List<Groups>();
                        Profiles p_item = null;
                        Groups g_item = null;

                        #region FOR I ITems
                        for (int i = 0; i < response["response"]["profiles"].Count(); i++) {
                            p_item = new Profiles() {
                                p_firstname = response["response"]["profiles"][i]["first_name"].ToString(),
                                p_lastname = response["response"]["profiles"][i]["last_name"].ToString(),
                                p_profile_image = response["response"]["profiles"][i]["photo"].ToString(),
                                p_uid = (int)response["response"]["profiles"][i]["uid"]
                            };
                            //prof_list.Insert(p_item);
                            prof_list.Add(p_item);
                        }
                        for (int i = 0; i < response["response"]["groups"].Count(); i++) {
                            g_item = new Groups() {
                                g_name = response["response"]["groups"][i]["name"].ToString(),
                                g_photo = response["response"]["groups"][i]["photo"].ToString(),
                                g_uid = (int)response["response"]["groups"][i]["gid"]
                            };
                            groups_list.Add(g_item);
                        }
                        for (int i = 0; i < response["response"]["items"].Count(); i++) {
                            if (response["response"]["items"][i].ToString().Contains("attachment")) {
                                string type = response["response"]["items"][i]["attachment"]["type"].ToString();
                                if (type == "photo" || type == "posted_photo")
                                    att_type = "photo";
                                else if (type == "audio")
                                    att_type = "audio";
                                else if (type == "link")
                                    att_type = "link";
                                else if (type == "note")
                                    att_type = "note";
                                else if (type == "poll")
                                    att_type = "poll";
                                else if (type == "graffiti")
                                    att_type = "graffiti";
                                else if (type == "video")
                                    att_type = "video";
                                else
                                    Debug.WriteLine("Error news.xmal postdown", type);
                            } else
                                att_type = "post";
                            Data item = null;
                            var items = response["response"]["items"];
                            string to_autorname = "";
                            string to_auth = "";
                            if ((int)items[i]["source_id"] > 0) {
                                var x = from z in prof_list
                                        where z.p_uid == (int)items[i]["source_id"]
                                        select z;
                                to_autorname = x.FirstOrDefault().p_profile_image;
                                to_auth = x.FirstOrDefault().p_firstname + " " + x.FirstOrDefault().p_lastname;
                            } else {
                                var x = from z in groups_list
                                        where z.g_uid == -(int)items[i]["source_id"]
                                        select z;
                                to_autorname = x.FirstOrDefault().g_photo;
                                to_auth = x.FirstOrDefault().g_name;
                            }
                        #endregion
                            #region SWTICH
                            switch (att_type) {
                                case "photo":
                                    item = new Data {
                                        attachment_type = "photo",
                                        image_src = items[i]["attachment"]["photo"]["src"].ToString(),
                                        image_src_big = items[i]["attachment"]["photo"]["src_big"].ToString(),
                                        text = items[i]["text"].ToString().Replace("<br>", "\n").Replace("&quot;", "\""),
                                        likes_count = (int)items[i]["likes"]["count"],
                                        pid_photo = (int)items[i]["attachment"]["photo"]["pid"],
                                        owner_id = (int)items[i]["attachment"]["photo"]["owner_id"],
                                        isLikeMe = Convert.ToBoolean((int)items[i]["likes"]["user_likes"]),
                                        uid = (int)items[i]["source_id"],
                                        post_id = (int)items[i]["post_id"],
                                        author_name = to_auth,
                                        image_uri = to_autorname,
                                        Date_Time = ((App)Application.Current).ConvertTimestamp(Convert.ToDouble((int)items[i]["date"])).ToString("dd MMM HH:mm:ss"),
                                        comm_count = (int)items[i]["comments"]["count"],
                                    };
                                    list.Insert(0, item);
                                    //list.Add( item);
                                    break;
                                case "graffiti":
                                    item = new Data {
                                        attachment_type = "graffiti",
                                        image_src = items[i]["attachment"]["graffiti"]["src"].ToString(),
                                        image_src_big = items[i]["attachment"]["graffiti"]["src_big"].ToString(),
                                        text = items[i]["text"].ToString().Replace("<br>", "\n").Replace("&quot;", "\""),
                                        likes_count = (int)items[i]["likes"]["count"],
                                        pid_photo = (int)items[i]["attachment"]["graffiti"]["gid"],
                                        owner_id = (int)items[i]["attachment"]["graffiti"]["owner_id"],
                                        isLikeMe = Convert.ToBoolean((int)items[i]["likes"]["user_likes"]),
                                        uid = (int)items[i]["source_id"],
                                        post_id = (int)items[i]["post_id"],
                                        author_name = to_auth,
                                        image_uri = to_autorname,
                                        Date_Time = ((App)Application.Current).ConvertTimestamp(Convert.ToDouble((int)items[i]["date"])).ToString("dd MMM HH:mm:ss"),
                                        comm_count = (int)items[i]["comments"]["count"],
                                    };
                                    list.Insert(0, item);
                                    // list.Add(item);
                                    break;
                                case "audio":
                                    item = new Data {
                                        attachment_type = "audio",
                                        audio_text = items[i]["attachment"]["audio"]["performer"].ToString() + " - " + items[i]["attachment"]["audio"]["title"].ToString(),
                                        audioUri = "",
                                        text = items[i]["text"].ToString().Replace("<br>", "\n").Replace("&quot;", "\""),
                                        likes_count = (int)items[i]["likes"]["count"],
                                        audioid = (int)items[i]["attachment"]["audio"]["aid"],
                                        isLikeMe = Convert.ToBoolean((int)items[i]["likes"]["user_likes"]),
                                        uid = (int)items[i]["source_id"],
                                        post_id = (int)items[i]["post_id"],
                                        author_name = to_auth,
                                        image_uri = to_autorname,
                                        Date_Time = ((App)Application.Current).ConvertTimestamp(Convert.ToDouble((int)items[i]["date"])).ToString("dd MMM HH:mm:ss"),
                                        comm_count = (int)items[i]["comments"]["count"],
                                    };
                                    list.Insert(0, item);
                                    // list.Add(item);
                                    break;
                                case "link":
                                    item = new Data {
                                        attachment_type = "link",
                                        url = items[i]["attachment"]["link"]["url"].ToString(),
                                        text = items[i]["text"].ToString().Replace("<br>", "\n").Replace("&quot;", "\""),
                                        title = items[i]["attachment"]["link"]["title"].ToString(),
                                        likes_count = (int)items[i]["likes"]["count"],
                                        isLikeMe = Convert.ToBoolean((int)items[i]["likes"]["user_likes"]),
                                        uid = (int)items[i]["source_id"],
                                        image_uri = to_autorname,
                                        author_name = to_auth,
                                        post_id = (int)items[i]["post_id"],
                                        Date_Time = ((App)Application.Current).ConvertTimestamp(Convert.ToDouble((int)items[i]["date"])).ToString("dd MMM HH:mm:ss"),
                                        comm_count = (int)items[i]["comments"]["count"],

                                    };
                                    list.Insert(0, item);
                                    // list.Add(item);
                                    break;
                                case "note":
                                    item = new Data {
                                        attachment_type = "note",
                                        text = items[i]["text"].ToString().Replace("<br>", "\n").Replace("&quot;", "\""),
                                        title = items[i]["attachment"]["note"]["title"].ToString().Replace("&quot;", "\""),
                                        image_src = items[i]["attachment"]["link"]["image_src"].ToString(),
                                        likes_count = (int)items[i]["likes"]["count"],
                                        isLikeMe = Convert.ToBoolean((int)items[i]["likes"]["user_likes"]),
                                        noteid = (int)items[i]["attachment"]["note"]["nid"],
                                        owner_id = (int)items[i]["attachment"]["note"]["owner_id"],
                                        uid = (int)items[i]["uid"],
                                        image_uri = to_autorname,
                                        author_name = to_auth,
                                        post_id = (int)items[i]["post_id"],
                                        Date_Time = ((App)Application.Current).ConvertTimestamp(Convert.ToDouble((int)items[i]["date"])).ToString("dd MMM HH:mm:ss"),
                                        comm_count = (int)items[i]["comments"]["count"],
                                    };
                                    list.Insert(0, item);
                                    //  list.Add(item);
                                    break;
                                case "post":
                                    item = new Data {
                                        attachment_type = "post",
                                        text = items[i]["text"].ToString().Replace("<br>", "\n").Replace("&quot;", "\""),
                                        likes_count = (int)items[i]["likes"]["count"],
                                        isLikeMe = Convert.ToBoolean((int)items[i]["likes"]["user_likes"]),
                                        uid = (int)items[i]["source_id"],
                                        image_uri = to_autorname,
                                        author_name = to_auth,
                                        post_id = (int)items[i]["post_id"],
                                        Date_Time = ((App)Application.Current).ConvertTimestamp(Convert.ToDouble((int)items[i]["date"])).ToString("dd MMM HH:mm:ss"),
                                        comm_count = (int)items[i]["comments"]["count"],
                                    };
                                    list.Insert(0, item);
                                    // list.Add(item);
                                    break;
                                case "poll":
                                    item = new Data {
                                        attachment_type = "poll",
                                        text = items[i]["text"].ToString().Replace("<br>", "\n").Replace("&quot;", "\""),
                                        likes_count = (int)items[i]["likes"]["count"],
                                        isLikeMe = Convert.ToBoolean((int)items[i]["likes"]["user_likes"]),
                                        uid = (int)items[i]["source_id"],
                                        image_uri = to_autorname,
                                        author_name = to_auth,
                                        poll_question = "Опрос: " + items[i]["attachment"]["poll"]["question"].ToString(),
                                        poll_id = (int)items[i]["attachment"]["poll"]["poll_id"],
                                        post_id = (int)items[i]["post_id"],
                                        Date_Time = ((App)Application.Current).ConvertTimestamp(Convert.ToDouble((int)items[i]["date"])).ToString("dd MMM HH:mm:ss"),
                                        comm_count = (int)items[i]["comments"]["count"],
                                    };
                                    list.Insert(0, item);
                                    // list.Add(item);
                                    break;
                                case "video":
                                    item = new Data {
                                        image_src = items[i]["attachment"]["video"]["image"].ToString(),
                                        image_src_big = items[i]["attachment"]["video"]["image_big"].ToString(),
                                        text = items[i]["text"].ToString().Replace("<br>", "\n").Replace("&quot;", "\""),
                                        likes_count = (int)items[i]["likes"]["count"],
                                        pid_photo = (int)items[i]["attachment"]["video"]["vid"],
                                        owner_id = (int)items[i]["attachment"]["video"]["owner_id"],
                                        attachment_type = "photo",
                                        isLikeMe = Convert.ToBoolean((int)items[i]["likes"]["user_likes"]),
                                        uid = (int)items[i]["source_id"],
                                        image_uri = to_autorname,
                                        author_name = to_auth,
                                        post_id = (int)items[i]["post_id"],
                                        Date_Time = ((App)Application.Current).ConvertTimestamp(Convert.ToDouble((int)items[i]["date"])).ToString("dd MMM HH:mm:ss"),
                                        comm_count = (int)items[i]["comments"]["count"],
                                    };
                                    list.Insert(0, item);
                                    // list.Add(item);
                                    break;
                            }
                            #endregion
                        }

                        //this.newslistBox.ItemsSource = null;

                        this.newslistBox.ItemsSource = list;
                        Debug.WriteLine("Itemsspurce updated");
                    } else {
                        ToastPrompt toast = new ToastPrompt();
                         //Debug.WriteLine(who.ToString());
                       //   Debug.WriteLine(who.FirstOrDefault()[4].ToString());
                        toast.TextOrientation = System.Windows.Controls.Orientation.Vertical;
                        toast.Message = "Нету новых новостей";
                        toast.MillisecondsUntilHidden = 2000;
                        toast.Show();
                    }

                   ProgBar.IsIndeterminate = false;
                    ProgBar.Visibility = Visibility.Collapsed;

                }...