nevermind96:
Now problem: When arduino doing a cnc program, when I press a button on C# program,it will send string "stop\n" to arduino and arduino will break out of the loop to stop step motor.
To achieve that your Arduino will need to check for a new message between each step. If you need accurately timed steps and a high step rate that may not be possible.
I have written a CNC program for my small lathe. The PC program interprets the GCode and sends instructions for one move at a time and the Arduino completes a move before checking for the data for the next move. Stopping the system can be achieved by NOT sending data for another move.
If there is need for an emergency stop then I just shut off the power to the stepper motors.
If you want the Arduino to receive data for several moves and store them in a queue and then be able to "jump" the queue to react to a STOP message then the amount of work to be done between steps will be that much greater.
...R