There is a listBox1 and listbox2 when I select values from the first one from the database the information is loaded and entered into the second one. I want to do that in the second thread, the information in the second is updated because data can change quickly. I wrote it all and made a button to update, everything works.
now I want without a button, so that the stream starts first and performs updates every х
seconds / minutes ...- and it works. But if I make updates more frequent (for clarity, 1500 ms, to catch an exception), when I click on the listbox, I get an exception (as I noticed before the listbox is updated), but not always, on a slow update, it can be “not met”, except Click right before the update (it seems to me, maybe not right).
I tried to make the listbox inactive at the moment of the start of the execution of a thread, but to turn it back on again at the end of the cycle does not help. In the exception, the Link to the object is written does not indicate an instance of the object. I do not understand how it does not indicate if the listbox is with values. Tell me why it occurs, and what to do with it, what would the user work as usual and at the same time the data was updated?
The code is long
listbox layout (as usual, only telerikovsky)
<telerik:RadListBox Name="LB_Ocenki_Semester"> <telerik:RadListBox.ItemTemplate > <DataTemplate> <Grid > <TextBlock TextWrapping="Wrap" Text="{Binding Path=nazvanieDisciplini, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="23" HorizontalAlignment="Left" Name="label24" VerticalAlignment="Top" Width="160" FontWeight="Bold" FontSize="14" /> <Label Content="{Binding Path=ocenka, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="160,-3,0,0" Height="23" Width="40" HorizontalAlignment="Left" Name="label136" VerticalAlignment="Top" FontWeight="Bold" FontSize="14" /> </Grid> </DataTemplate> </telerik:RadListBox.ItemTemplate> </telerik:RadListBox> есть методы, например для получения таблицы дисциплин,оценок у студента на выбранном семестре public DataTable Get_Semester_Students_Ocenki(string Zachetka,string Semester) { MyAdapter.SelectCommand = new SqlCommand(string.Format("SELECT YearName,Zachetka,Disciplini.Disciplina,Ocenka as ocenka,Primechanie,NazvanieDisciplini as nazvanieDisciplini FROM UspevaemostOcenki INNER JOIN Disciplini on Disciplini.Disciplina=UspevaemostOcenki.Disciplina where zachetka={0} and YEARNAME={1}", Zachetka, Semester), MyConnection); Table_Semester_Students_Ocenki.Clear(); try { MyAdapter.Fill(Table_Semester_Students_Ocenki); } catch { } return Table_Semester_Students_Ocenki; } .... ..... и стоит привязка листбокса и DataView,который получается из запроса LB_Ocenki_Semester.ItemsSource = new DataView(Con.Get_Semester_Students_Ocenki(Students_Semester_Zachetka_Selected.Text.ToString().Trim(), Selected_Semester_Nomer.Text.ToString().Trim())); пока всё без проблем. а позже добавляю кнопку "автоматически обновлять" и пишу обработчик *thread = new Thread(this.Proc); thread.Priority = ThreadPriority.Highest; thread.IsBackground = true; thread.Start();* public void Proc() { while (true) { this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (ThreadStart)delegate() { Refresh_Selected_Student_Semester_Info(); }); Thread.Sleep(1500);//для наглядности-ставлю часто } } (Con- это sqlconnection,) public void Refresh_Selected_Student_Semester_Info() { Con.MyAdapter.SelectCommand = new SqlCommand(string.Format("select UspevaemostOcenki.YearName,Disciplini.Disciplina,NazvanieDisciplini, Ocenka,Primechanie,Years.YearName as YN from UspevaemostOcenki inner join Disciplini on UspevaemostOcenki.Disciplina = Disciplini.Disciplina inner join Years on Years.Nomer = UspevaemostOcenki.YearName where zachetka={0} and UspevaemostOcenki.YearName={1}", Students_Semester_Zachetka_Selected.Text.ToString().Trim(), Selected_Semester_Nomer.Text.ToString().Trim()), Con.MyConnection); Con.Table_Semester_Students_Ocenki.Clear(); try { Con.MyAdapter.Fill(Con.Table_Semester_Students_Ocenki); } catch { } } Это всё работает, если на него "не дышать", как только начинаю много клацать-вылетает исключение