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.