回复 3楼cqtk的帖子
从我这边的调试结果来看,因为使用多线程导致在重绘控件时出错,我对代码进行了一点改动,主要是修改了TestError方法
- namespace SpreadErrorDemo
- {
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
- BackgroundWorker backgroundWorker;
- private delegate void InvokeCallback(BackgroundWorker backgroundWorker, DoWorkEventArgs e);
-
- private void Form2_Load(object sender, EventArgs e)
- {
- this.fpSpread1.ActiveSheet.ColumnHeader.AutoText = HeaderAutoText.Numbers;
- backgroundWorker = new BackgroundWorker();
- backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
- }
- private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
- {
- BackgroundWorker worker = sender as BackgroundWorker;
- this.TestError(worker, e);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- backgroundWorker.RunWorkerAsync();
- }
- public void TestError(BackgroundWorker backgroundWorker, DoWorkEventArgs e)
- {
- if (this.InvokeRequired)
- {
- this.Invoke(new InvokeCallback(TestError), new object[] { backgroundWorker, e });
- }
- else
- {
- this.fpSpread1.ActiveSheet.ColumnHeader.Columns.Clear();
- this.fpSpread1.ActiveSheet.ColumnHeader.Columns.Count = 10000;
- this.fpSpread1.ActiveSheet.RowHeader.Rows.Clear();
- this.fpSpread1.ActiveSheet.RowHeader.Rows.Count = 10000;
- //还原列行数
- this.fpSpread1.ActiveSheet.ColumnCount = 10000;
- this.fpSpread1.ActiveSheet.RowCount = 10000;
- int ttt = 0;
- for (int i = 0; i < 1000000000; i++)
- {
- ttt++;
- }
- }
- }
- }
- }
复制代码 |