Hello,
public System.Threading.Timer AsyncProgramChangeTimer = null;
public void MyStartTimer()
{
lock (this)
{
AsyncProgramChangeTimer = new System.Threading.Timer((o) =>
{
if (ProgramChangeDone == false)
{
//do whatever
Trace.WriteLine("Timer was coming!!!");
Action<string> DelegateTeste_ModifyText = THREAD_MOD;
Invoke(DelegateTeste_ModifyText, $"Timer was coming!!! {DateTime.Now}");
AsyncProgramChangeTimer.Change(2000, Timeout.Infinite);
}
else
{
Trace.WriteLine("Timer no repeat!!!");
}
}, null, 0, Timeout.Infinite);
}
}
private void THREAD_MOD(string test)
{
txtStatus.Text += Environment.NewLine + test;
}
private void btnStopTimer_Click(object sender, EventArgs e)
{
ProgramChangeDone = !ProgramChangeDone;
MyStartTimer();
}
My goal.
A) Action or Func
How do I have to write it if I want a return value?
How do I have to write it if I want to have one return value and two passing parameters?
How do I have to write it if I want to have no return value and three passing parameters?
B) Lock
Do I need the lock so no one can access it?
C) Via a button I would like to switch the timer monitoring on or off.
D) Invoke or Dispatcher ?
Update the controls, which mechanism is correct?
Is this correct in my example?