0

I want to use multithreading for the first time as I understood, there is 2 laws to respect: -Threads can be used only with void's -One cannot use Threads to change something in a windows form(unless you use delegates).

So I code my macro by respect to this rule, here is my code :

public void exec_RT(string tickername, bool isSubIndex)
{
    DataTable RT_dt = Price_dt(tickrname, isSubIndex);
    Infragistics.Win.UltraWinChart.UltraChart toplot = new Infragistics.Win.UltraWinChart.UltraChart();
    toplot = forms.Real_timeAlpha;
    configgraph(RT_dt, toplot);
}

My problem is that the function Price_dt return a datatable :

public DataTable Price_dt(string tickername, bool isSubIndex)
{
    DoMyThing();
    return real_time;
}

So my question is how can I make a void return a datatable ?

Thanks

Rémi
  • 3,867
  • 5
  • 28
  • 44
francops henri
  • 507
  • 3
  • 17
  • 29

3 Answers3

0

you can use class members for storing the datatable.

public DataTable Price_dt(string tickername, bool isSubIndex)
{
    DoMyThing();
    this.setDT(real_time);
}

i'm pretty sure you have to (/should) use an invoke for setting the table (therefore the function).

you can reffer the "stored" table in every other part of your class.

hope this helps

Alex
  • 1,857
  • 3
  • 36
  • 51
0

You could just pass the DataTable to your method and work in that table. Since DataTable is a reference type all your modification are on the original object to witch both variables reference (your original variable and the one from inside Price_dt).

Your method would go from this

public DataTable Price_dt(string tickername, bool isSubIndex)
{
    DoMyThing();
    return real_time;
}

to this

public void Price_dt(DataTable yourDataTable, string tickername, bool isSubIndex)
{
    //modify yourDataTable here
    DoMyThing();
}
Rémi
  • 3,867
  • 5
  • 28
  • 44
  • you still can't return `real_time` you have to `yourDataTable = real_time` (i hope that `real_time` is the table ... it's not clear (for me) – Alex Aug 23 '13 at 14:38
  • @Alex of course I simply add forgot to remove the `return` statement. the datatable will be modified outside of the method without having to return it. – Rémi Aug 23 '13 at 14:41
  • I just tried it the idea is nice but it does not work , the Datatable yourDataTable come back empty in exec_RT – francops henri Aug 23 '13 at 15:04
  • @francopshenri how have you tryed? I use this kind of behavior at several place in my code and it work properly – Rémi Aug 23 '13 at 15:28
0

You could try to use a global variable to store your DataTable in

public void exec_RT(string tickername, bool isSubIndex)
    {
        DataTable RT_dt = Price_dt(tickrname, isSubIndex);
        Infragistics.Win.UltraWinChart.UltraChart toplot = new Infragistics.Win.UltraWinChart.UltraChart();
        toplot = forms.Real_timeAlpha;
        //global variable of the type DataTable
        globalTable = RT_dt;
        configgraph(RT_dt, toplot);
    }

And use globalTable for whatever you may need later on.

Chuk Ultima
  • 987
  • 1
  • 11
  • 21