Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I can't update a text box via a timer.
This is the declaration of the texbox and the property

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


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


And this is the timer.

System.Timers.Timer timer = new System.Timers.Timer(1000);
      timer.AutoReset = true; 
      timer.Elapsed += TimerCallback;
      timer.Start();

      using (TransactionScope ts = new TransactionScope())
      {
         importResult = _dsMain.ImportData_RIL();
         if (importResult)
              ts.Complete();
       }
  timer.Stop();


And the procedure

void TimerCallback(object sender, EventArgs e)
        {
           RowsImport=  UTILITY.General.PARAM_PROG_RIL_COUNT;
           OnPropertyChanged("RowsImport");

        }


Unfortunately this code doesn't work and the textbox never updates !! :-(


p.s.
this is the declaration of
public static string PARAM_PROG_RIL_COUNT { get; set; }  


What I have tried:

In the
TimerCallback
I tried to substitude this code

RowsImport=  UTILITY.General.PARAM_PROG_RIL_COUNT.ToString();
     OnPropertyChanged("RowsImport");


with.....

1 try
 Application.Current.Dispatcher.BeginInvoke(               
      DispatcherPriority.Background,
           new Action(() => RowsImport =  UTILITY.General.PARAM_PROG_RIL_COUNT;)));

2 try
 Application.Current.Dispatcher.Invoke(
      ispatcherPriority.Background,
           new Action(() => RowsImport = UTILITY.General.PARAM_PROG_RIL_COUNT
              OnPropertyChanged("RowsImport")));


3 try
    Application.Current.Dispatcher.Invoke(() =>
         RowsImport = UTILITY.General.PARAM_PROG_RIL_COUNT);

4 try
   Application.Current.Dispatcher.BeginInvoke(
         DispatcherPriority.Background,
               new Action(() => {this.RowsImport = UTILITY.General.PARAM_PROG_RIL_COUNT;}));
5 try
     Application.Current.Dispatcher.BeginInvoke(new Action(() => this.RowsImport = 
         UTILITY.General.PARAM_PROG_RIL_COUNT),
                System.Windows.Threading.DispatcherPriority.Background, null);
                    Thread.Sleep(200);

6 try
    Application.Current.Dispatcher.BeginInvoke(new Action(() => RowsImport = 
        UTILITY.General.PARAM_PROG_RIL_COUNT)
                System.Windows.Threading.DispatcherPriority.Background, null);
                   Thread.Sleep(200);
7 try
            Application.Current.Dispatcher.Invoke(() =>
            {
                RowsImport= UTILITY.General.PARAM_PROG_RIL_COUNT;
            });



But nothing to do.. ! Doesn't work....
How can I resolve ??

Thanks to everyone who will help me.
Posted
Updated 13-Feb-22 6:44am

1 solution

 
Share this answer
 
Comments
antobaro 13-Feb-22 14:43pm    
What do you mean ? Tell me in other words
Jo_vb.net 13-Feb-22 14:45pm    
Why did you start a new topic and did not answer to the suggestions / questions you got at your topic from saturday?
antobaro 13-Feb-22 15:14pm    
Because I want to try a new scenario for the resolution. Is it a problem ?
Jo_vb.net 13-Feb-22 15:38pm    
I do not understand what you are doing.

I would:

1) Try to pass an instance of your Viewmodel as parameter / argument to your timer method to allow access to the Property.

2) add UpdateSourceTrigger=PropertyChanged

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

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