线程间操作无效: 从不是创建控件的线程访问它

 a(this.ViewModel.WhenAnyValue(m => m.Datas).Subscribe(Datas =>
                {
                    try
                    {
                        #region  法一
                        //new Thread(() =>
                        //{
                        //    for (int i = 0; i < Datas.Rows.Count; i++)
                        //    {
                        //        Action<int> c = new Action<int>(Action2Test);
                        //        Invoke(c, i);
                        //    }
                        //}).Start();
                        #endregion

                        #region  法二
                        //for (int i = 0; i < Datas.Rows.Count; i++)
                        //{
                        //    Action<int> c = new Action<int>(Action2Test);
                        //    Invoke(c, i);
                        //}
                        #endregion

                        #region  法三
                        for (int i = 0; i < Datas.Rows.Count; i++)
                        {
                            this.Invoke(new Action(() =>
                            {
                                this.cbCableDataList.Properties.Items.Add(i);
                            }));


                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {

                        throw;
                    }

                }));

 

posted on 2022-02-17 11:10  冰魂雪魄  阅读(93)  评论(0)    收藏  举报

WPF框架交流群:C#.net. WPF.core 技术交流�      C#WPF技术交流群:C#.net. WPF.core 技术交流�     WPF技术大牛交流群:C#.net. WPF.core 技术交流�