Starting a new Thread within a Macro
Posted: Fri Mar 17, 2023 10:46 am
Hello,
I did some searches before, but have not found any "thread" that adresses this topic,
maybe because there are too many results if searching for "Thread". So I hope for the
older members that this is not asked again and again.
I have a constant surface speed (lathe) macro running in a macroloop to adjust
Spindle speed during the moves on the fly.
But it would be nice to have it not always on and that it can be called like any other
code from MDI or within a G-Code file.
If there is a call for a code execution within a macro,
the macro blocks and it´s execution is halted until the code
is finished, so the following does not work:
The while loop starts after the finished move.
I also tested the following and this seems to work:
So my question is: Is it ok to do so, or may this result in some issues I´m not aware?
Best regards
Dominik
P.S.: As far as I know there is no comprehensive manual for macros, e.g. what can be done or should not be done,
if so, please point me to the location.
I did some searches before, but have not found any "thread" that adresses this topic,
maybe because there are too many results if searching for "Thread". So I hope for the
older members that this is not asked again and again.
I have a constant surface speed (lathe) macro running in a macroloop to adjust
Spindle speed during the moves on the fly.
But it would be nice to have it not always on and that it can be called like any other
code from MDI or within a G-Code file.
If there is a call for a code execution within a macro,
the macro blocks and it´s execution is halted until the code
is finished, so the following does not work:
- Code: Select all
exec.Code("G1 X5");
while(exec.IsMoving()==true)
{
//Adjust Speed
}
The while loop starts after the finished move.
I also tested the following and this seems to work:
- Code: Select all
Thread thread = new Thread(() =>
{
exec.Code(gCodeString);
});
thread.Start();
//Wait for move to start
while(exec.IsMoving()==false)
{
Thread.Sleep(threadSleep);
}
//Adjust Speed during Movement
while(exec.IsMoving()==true)
{
//Adjust Speed here
}
So my question is: Is it ok to do so, or may this result in some issues I´m not aware?
Best regards
Dominik
P.S.: As far as I know there is no comprehensive manual for macros, e.g. what can be done or should not be done,
if so, please point me to the location.