posted
I have a lovely, working C# application. Now I need to add a function that runs in the background at a constant rate (eg 10 Hz), using one variable from the main part of the program and adjusting several others.
I can create a standalone program using a Timer (simply following the .NET documentation example) that works fine, but my attempts to use it in my app have been unsuccessful. That is, I can compile just fine, but then it doesn't do anything.
I haven't dealt with multiple threads before, but I think this may indeed be a simple (so to speak) solution.
Posts: 105 | Registered: Oct 2005
| IP: Logged |
Most threading brings issues of concurrency into it- that is, shared variables/objects that one thread accesses (and changes) affecting other threads that are trying (or will try) to use that used/changed variable/object, leading to race conditions. This Article gives some information on interlocking threads and how to make them safer without causing race conditions or lockups.
Posts: 1346 | Registered: Jun 1999
| IP: Logged |
posted
The Timer class does create its own thread. You should make a Service app with a Timer. Then, confirm that the timer works by doing a simple test in the timer event (10 sec interval) like write some text to a file. That way you know the timer works and can move on to your real logic.
Posts: 90 | Registered: Apr 2006
| IP: Logged |
That's what I was starting to figure out yesterday. However, as the paper concerning this project is due today, I'm going to try a different approach: performing my would-be-Timer task everytime a MIDI message comes in.
AT,
I was wondering how long it would take...
Posts: 105 | Registered: Oct 2005
| IP: Logged |