[C#从外部计时器类刷新数据网格

问题描述 投票:0回答:1

我每次尝试尝试从外部Timer类刷新datagridview时,都会出错:不允许使用线程综合]

Form1.cs:

public void Main_Window_Load(object sender, EventArgs e)
    {


        SetDatagridView();            

    }

 public void SetDatagridView()
    {
        DataTable MBServices = new DataTable();
        DataView MBServicesVW = new DataView();

        MBServices = getMasterServicetblOverview("8");
        MBServices.Columns.Add("State", typeof(Image));

        MBServices.Columns.Remove("state");
        MBServicesVW = new DataView(MBServices);
        dataGridSHToverview.DataSource = MBServicesVW;
    }

Timer.cs:
  class Timer
{
    public class NamedTimer : System.Timers.Timer
    {

    }

    public static void TimerDo()
    {

            Timer timer = new Timer();
            timer.Interval =  (60000);
            timer.Elapsed += Main_Tick;
            timer.AutoReset = false;
            timer.Start();
    }

    public static void Main_Tick(object sender, EventArgs args)
    {
            //there a want to call SetDatagridView()       
    }     
}

timerDo()将在主类中调用。

感谢您的帮助

我每次尝试尝试从外部Timer类刷新datagridview时都会出错:不允许使用线程综合Form1.cs:public void Main_Window_Load(object sender,EventArgs ...

c# timer windows-forms-designer
1个回答
0
投票
我建议您使用事件模式。
© www.soinside.com 2019 - 2024. All rights reserved.