Progressbarusing делегаты в C#
iam работает с прогресс-баром в приложении c# windows, после чтения файла из текста iam добавляется в текстовое поле, но прогресс-бар не работает должным образом, прогресс-бар остается в том же положении, и код получает выполнение, пожалуйста, решите эту проблему.
я делаю эту операцию при выборе ячейки в gridview_cellclick
public static Thread thread1; public string strSelectedfile; private void GridView_integration_CellClick(object sender, GridViewCellEventArgs e) { try { if (e.RowIndex != -1 && e.ColumnIndex != -1) { strSelectedfile = Application.StartupPath + "\\" + GridView.Rows[e.RowIndex].Cells[0].Value.ToString(); txtReadfile.Text = string.Empty; progressBar.Visible = true; progressBar.Style = ProgressBarStyle.Marquee; thread1 = new Thread(new ThreadStart(loadTextfile)); thread1.Start(); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } private void loadTextfile() { setTextSource(strSelectedfile); } internal delegate void SetDelegate(string textvalue); private void setTextSource(string textvalue) { if (this.InvokeRequired) { this.Invoke(new SetDelegate(setTextSource), textvalue); } else { txtReadfile.Text = File.ReadAllText(textvalue); thread1.Abort(); progressBar.Visible = false; } }
Что я уже пробовал:
public static Thread thread1; public string strSelectedfile; private void GridView_integration_CellClick(object sender, GridViewCellEventArgs e) { try { if (e.RowIndex != -1 && e.ColumnIndex != -1) { strSelectedfile = Application.StartupPath + "\\" + GridView.Rows[e.RowIndex].Cells[0].Value.ToString(); txtReadfile.Text = string.Empty; progressBar.Visible = true; progressBar.Style = ProgressBarStyle.Marquee; thread1 = new Thread(new ThreadStart(loadTextfile)); thread1.Start(); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } private void loadTextfile() { setTextSource(strSelectedfile); } internal delegate void SetDelegate(string textvalue); private void setTextSource(string textvalue) { if (this.InvokeRequired) { this.Invoke(new SetDelegate(setTextSource), textvalue); } else { txtReadfile.Text = File.ReadAllText(textvalue); thread1.Abort(); progressBar.Visible = false; } }