الخميس، 11 يونيو 2015

System.Threading.Timer and Control.Invoke

private System.Threading.Timer _updateCommentsTimer;
_updateCommentsTimer = new System.Threading.Timer(UpdateComments);
_updateCommentsTimer.Change(0, 3500);
_timerStarted = true;
private void UpdateComments(object status)
{
  // do what u want, invoke UI maybe required..
  if (txtBoxProcess.InvokeRequired)
                            {
                                txtBoxProcess.Invoke(new MethodInvoker(() =>
                                {
                                      txtBoxProcess.Text="ant text";//
                                }));
                            }
                            else
                            {
                                      txtBoxProcess.Text="";
                            }
}

// you can dispose the timer (stop)..
if (_timerStarted)
   _updateCommentsTimer.Dispose();  

ليست هناك تعليقات:

إرسال تعليق