Maarten

Maarten

  • NA
  • 1
  • 0

a little help before choosing the multi threaded path

Apr 17 2009 7:01 AM

Hello,

I'm trying to find out if multi-threading would be worth the hassle to implement in my application. I'm developing a small application for controlling a 2-Axis CNC engravingmachine. I'm using .NET to create the GUI. All other functions for controlling the machine are self developed with C# and OO. Let me first try to give a short clear view of the components involved:

The application starts in a Drawing mode where a user can make a simpel drawing through the GUI. He can then change to a different mode to execute the machining of this drawing. All the fysical inputs and outputs of the machine are interfaced through the USB. And all the API's are available through C#

When machining I need to cycle a check on certain inputs, when these inputs change during machining it will raise an event as an Alarm or Notification to stop the machine in an emergency case. (when it reaches its limitswitch for example)

As far as i have read on the subject this would my idea to implement multi threading for my application:

The main thread starts and runs the drawing mode and GUI, when the user starts the machining operation a second thread will be started. The main thread will remain idle but needs to display information during the process, the update frequencie of this info is a secondary objective though. The main thread will also be unaccesible for the user while the second thread is running.

The second thread is, besides the infomessage-data, seperated from the main thread. No other common variables used. It will run a machining cycle that executes different instructions for the machine like 'turn on spindle' or 'move X-axis'. These instructions are contained in a generic List  and will probably be called in a foreach loop or do while loop with some added time to have a periodic cycle.

Next I want to create a third thread that is gonna do the state check on the I/O's. I'm thinking of using also a while loop with a sleep function to keep inputchecks about 40-50ms apart.In case a certain input is changed, an event will be raised. This event should have some control over the second thread so it can stop the machining cycle if nessecary. Sort of like a master-slave principle where the inputcheck thread is master over the machining thread. Also no needed common data between the other threads.

 

Would this scenario provide a good working model or would it be a multi threading frankenstein.

Any info or thoughts on the subject would be great.

thanks in advance,

Bender