C
# Cyrille37 #
Hello,
I've got a method which could be called by a UI Event and a Timer.
I would like to be shure that not 2 concurents calls append.
I don't know if I can use System.Threading.Monitor.
And if System.Threading.Monitor is the right method, which object I've to
Monitoring ?
Here is a peace of code that should show the context.
Can you help me by telling me where and how to put the critical section.
<code>
UserControl userControl1 ;
Timer timer1 ;
....
private void userControl1_VisibleChanged(object sender, System.EventArgs e)
{
if( this.Visible )
{
return ;
}
// If it comes invisible, send the message.
SendMsg();
// timer is not active while the form is not visible.
this.timer1.Stop();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
// every N ticks, send the message
SendMsg();
}
// here should be the critical section
void SendMsg()
{
this.timer1.Stop();
// ... send the message
this.timer1.Start();
}
</code>
Thanks for your help.
cyrille
I've got a method which could be called by a UI Event and a Timer.
I would like to be shure that not 2 concurents calls append.
I don't know if I can use System.Threading.Monitor.
And if System.Threading.Monitor is the right method, which object I've to
Monitoring ?
Here is a peace of code that should show the context.
Can you help me by telling me where and how to put the critical section.
<code>
UserControl userControl1 ;
Timer timer1 ;
....
private void userControl1_VisibleChanged(object sender, System.EventArgs e)
{
if( this.Visible )
{
return ;
}
// If it comes invisible, send the message.
SendMsg();
// timer is not active while the form is not visible.
this.timer1.Stop();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
// every N ticks, send the message
SendMsg();
}
// here should be the critical section
void SendMsg()
{
this.timer1.Stop();
// ... send the message
this.timer1.Start();
}
</code>
Thanks for your help.
cyrille