Mutex Not Working
-
Know any good ones ;) entered commandSetBlockParameter in thread: 20 Exited commandSetBlockParameter in thread: 20 entered queryBlockParameter in thread: 20 entered commandSetBlockParameter in thread: 20 Exited commandSetBlockParameter in thread: 20 entered queryBlockParameter in thread: 20 entered commandSetBlockParameter in thread: 20 Exited commandSetBlockParameter in thread: 20 entered queryBlockParameter in thread: 20 Exited queryBlockParameter in thread: 20 Exited queryBlockParameter in thread: 20 That said, Let me add another issue. This is in a timer loop. The timer was ticking before the last passthrough finished. I can disable the timer until the loop completes than reenable it. This may be the only way to fix this. However, The same problem happens elsewhere when I subscribe to an event and I end up writing two values. I will have to fix this and do more testing. Please do not give up on me. You have been a HUGE help. If I respond in a day, will you be here, or should I start a new thread? Thanks so much... Dwayne ***************** "We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
ok. I have updated the rest of the code and am able to stop it from happening in the timer by disabling it and reenabling it after the loop completes. The same problem still applies to when I subscribe to an event, this launches a new set of code (still in the same thread according to the output) that runs and overlaps. For instance... the original description of two userControls each calling the same communications function. When the user selects the second control it send a stop message to the first control, but that does not stop the form from continuing through it's timer poll. It is in these transitions that the problem still happens. -Dwayne ***************** "We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
-
Know any good ones ;) entered commandSetBlockParameter in thread: 20 Exited commandSetBlockParameter in thread: 20 entered queryBlockParameter in thread: 20 entered commandSetBlockParameter in thread: 20 Exited commandSetBlockParameter in thread: 20 entered queryBlockParameter in thread: 20 entered commandSetBlockParameter in thread: 20 Exited commandSetBlockParameter in thread: 20 entered queryBlockParameter in thread: 20 Exited queryBlockParameter in thread: 20 Exited queryBlockParameter in thread: 20 That said, Let me add another issue. This is in a timer loop. The timer was ticking before the last passthrough finished. I can disable the timer until the loop completes than reenable it. This may be the only way to fix this. However, The same problem happens elsewhere when I subscribe to an event and I end up writing two values. I will have to fix this and do more testing. Please do not give up on me. You have been a HUGE help. If I respond in a day, will you be here, or should I start a new thread? Thanks so much... Dwayne ***************** "We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
I'm baffled. I can't imagine how you can possibly get such a result. Look at this, ugly, code:
using System;
using System.Threading;
using System.IO;namespace ConsoleTestApp
{
public class MyClass
{
private Timer timer;public static void Main(string\[\] args) { MyClass myClass = new MyClass(); using (FileStream fileStream = File.OpenWrite(@"C:\\test.txt")) { using (StreamWriter sw = new StreamWriter(fileStream)) { Console.SetOut(sw); myClass.Start(); Thread.Sleep(10000); myClass.Stop(); Thread.Sleep(1000); } } } public void Start() { timer = new Timer( new TimerCallback(MyTimerCallback), null, 0, 500 ); } public void Stop() { timer.Dispose(); } private void MyTimerCallback(object state) { for (int i = 0; i < 5; i++) { Foo(); } } private void Foo() { lock (this) { Console.WriteLine("Entered lock block in thread " + Thread.CurrentThread.GetHashCode()); Thread.Sleep(100); Console.WriteLine("Leaving lock block in thread " + Thread.CurrentThread.GetHashCode()); } } }
}
It doesn't produce the outcome you get. Does your code look something like this? "God doesn't play dice" - Albert Einstein "God not only plays dice, He sometimes throws the dices where they cannot be seen" - Niels Bohr
-
I'm baffled. I can't imagine how you can possibly get such a result. Look at this, ugly, code:
using System;
using System.Threading;
using System.IO;namespace ConsoleTestApp
{
public class MyClass
{
private Timer timer;public static void Main(string\[\] args) { MyClass myClass = new MyClass(); using (FileStream fileStream = File.OpenWrite(@"C:\\test.txt")) { using (StreamWriter sw = new StreamWriter(fileStream)) { Console.SetOut(sw); myClass.Start(); Thread.Sleep(10000); myClass.Stop(); Thread.Sleep(1000); } } } public void Start() { timer = new Timer( new TimerCallback(MyTimerCallback), null, 0, 500 ); } public void Stop() { timer.Dispose(); } private void MyTimerCallback(object state) { for (int i = 0; i < 5; i++) { Foo(); } } private void Foo() { lock (this) { Console.WriteLine("Entered lock block in thread " + Thread.CurrentThread.GetHashCode()); Thread.Sleep(100); Console.WriteLine("Leaving lock block in thread " + Thread.CurrentThread.GetHashCode()); } } }
}
It doesn't produce the outcome you get. Does your code look something like this? "God doesn't play dice" - Albert Einstein "God not only plays dice, He sometimes throws the dices where they cannot be seen" - Niels Bohr
Not really. It would be more like:
using System;
using System.Threading;
using System.IO;namespace ConsoleTestApp
{
public class MyClass
{
private Timer timer;public static void Main(string\[\] args) { MyClass myClass = new MyClass(); timer.Interval=100; timer.Enabled=true; timer.Tick += new System.EventHandler(this.timer\_Tick); } public void timer\_Tick() { Foo1(); Foo2(); } private void Foo1() { lock(LockClass.LOCK\_OBJECT) { Console.WriteLine("Entered lock block in thread " + Thread.CurrentThread.GetHashCode()); Thread.Sleep(100); Console.WriteLine("Leaving lock block in thread " + Thread.CurrentThread.GetHashCode()); } } private void Foo2() { lock(LockClass.LOCK\_OBJECT) { Console.WriteLine("Entered lock block in thread " + Thread.CurrentThread.GetHashCode()); Thread.Sleep(200); Console.WriteLine("Leaving lock block in thread " + Thread.CurrentThread.GetHashCode()); } } } public class LockClass { public static readonly object LOCK\_OBJECT = new object(); }
}
This was typed so my syntax may not be exact. There is also no start and stop events. this is mainly to let you get the idea. As you can see it takes more time for the Foos to run that it takes for the timer to start the next tick. so the timer ticks and foo1 is started again while foo2 is still running. So instead of this... I am putting the following in the Timer code:
public void timer_Tick()
{
try
{
timer.enabled = false;
Foo1();
Foo2();
}
finally
{
timer.enabled = true;
}
}It is a patch, but it works. I am uncertain of the TimerCallBack. I will spend tonight figuring out that. Perhaps I am not using the Timer properly. I must admit, I had/have little experience with the timers. The other problem is when I subscribe to an event:
using System;
using System.Threading;
using System.IO;namespace ConsoleTestApp
{
public class MyClass
{
private Timer timer;
private bool doStop1;
private bool doStop2;