Ryden Choi Ryden Choi - 1 day ago 4
C# Question

How can I change invoke(new action) under c# 3.0

I made a WinForm program under .Net Framework 4.5

And now I trying to make it under .Net Framework 3.0

Using thread, call the "Control.Invoke" to Datagridview, but it's not work..

My Code is like this

private void btnStart_Click(object sender, EventArgs e)
{
Thread th = new Thread(new ThreadStart(StartAnalyseTheSite));
th.IsBackground = true;
th.Start();
}

private void StartAnalyseTheSite()
{
InsertWebApplicationInfo();
SelectWebApplicationInfo();
}

private void InsertWebApplicationInfo()
{
DoSomething...
}

private void SelectWebApplicationInfo()
{
this.Invoke(new Action(() => { grdWebApplication.DataSource = dtwebApp; }));
}


And

this.Invoke(new Action(() => { grdWebApplication.DataSource = dtwebApp; }));

This code is not work...

Error Message is ->

'Action' does not contain a constructor that takes 1 arguments

How can I change that code?? Somebody help me

Answer

You can use such code:

this.Invoke(new MethodInvoker(delegate() { /*Do sommething*/ }));
Comments