Click here to Skip to main content
15,357,358 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All, my issue is: why a binding variable doesn't refresh in a tread ?

this is my Scenario:

in my view I have defined this textbox

<TextBlock Text="{Binding RowsImport, Mode=TwoWay}" />

and this is the property

private string _RowsImport;
public string RowsImport
{
    get { return _RowsImport; }
    set
    {
        _RowsImport = value;
        base.OnPropertyChanged("RowsImport");
    }
}


Now, in this method Import I assign a value numeric in UTILITY.General.PARAM_PROG_RIL_COUNT
this is the declaration
public static string PARAM_PROG_RIL_COUNT { get; set; }


public bool Import()
{
... bla... bla..

  nrRowsImported++;

  UTILITY.General.PARAM_PROG_RIL_COUNT = "count" + nrRowsImported.ToString().Trim();

  return true;
}



I start the timer and call the method

Timer t = new Timer(TimerCallback, null, 0, 10);

  using (TransactionScope ts = new TransactionScope())
        {
           importResult = Import();
               if (importResult)
                    ts.Complete();
        }
        t.Dispose();


this is void TimerCallback
private  void TimerCallback(Object o)
{
    RowsImport= "Rows" + UTILITY.General.PARAM_PROG_RIL_COUNT;
    Console.WriteLine(RowsImport);
}


Now, while the TransactionScope is running I expect the variable RowsImport to be updated, but doesn't work.

What I have tried:

Only in this mode I see the variable is change at the end, with a MessageBox


using (TransactionScope ts = new TransactionScope())
      {
         importResult = Import();
             if (importResult)
                  ts.Complete();
      }
      t.Dispose();

        MessageBox.Show(RowsImport);




How can I resolve ?

In summary.
I have a variable in binding.
I execute a transaction that invokes a method (Import)

In the Import method I assign the progressive number of the readings to the variable.

Unfortunately, between the transaction and the Import method there is no way to reach the binding and therefore I am forced to use a timer.

I hope I was clear.

Thanks to those who will help me.
Posted
Updated 12-Feb-22 9:50am
v2
Comments
Jo_vb.net 12-Feb-22 9:15am
   
Is

Console.WriteLine(RowsImport)

not updated or

<textblock text="{Binding RowsImport, Mode=TwoWay}">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900