Using Task to Setup a DataGridView

67 views Asked by At

I am using Task() to offload work during the start of my application. And it was working fine. And then it wasn't... If I've got it right, I am making a copy of 'SomeStatusradGridView'. Which means I should be fine, except I get the following error:

This exception was originally thrown at this call stack: [External Code] MOSES.Logic.HumanResources.HumanResources.SomeStatusradGridView(Telerik.WinControls.UI.RadGridView) in HumanResources.cs MOSES.Presentation.Main.Main_Load.AnonymousMethod__15_0() in Main.cs [External Code]

Here is the code I am having the problem with:

public Main()
{
    Task<RadGridView> task2 = Task<RadGridView>.Factory.StartNew(() =>
    {
        return HumanResources.SetSomeStatusView(SomeStatusradGridView);
    });

    SomeMorkWork();

    SomeStatusradGridView = = task2.Result;
}

public static RadGridView SetSomeStatusView(RadGridView rgv)
{
    List<T> someList = new List<T>();
    rgv.DataSource = someList;
    return rgv;
}

Now, if I make the following change:

public static RadGridView SetSomeStatusView(RadGridView rgv)
{
    RadGridView fresh = new RadGridView();
    List<T> someList = new List<T>();
    fresh.DataSource = someList;
    return fresh;
}

I do not get the error, but that seems to indicate that a copy is not being made. Any insight would be great.

Thank you!

1

There are 1 answers

1
Scooter On

OK... No sooner do I post the question and I discover the answer...

SomeStatusradGridView had Focus, or was Activated, in the Designer when it did not before. I set focus to a different control. Main() come up just fine. Reset Focus back to SomeStatusradGridView and the error re-presented itself.