compewter_numerical
if you see the first time i wrote here you can see that first step was to get the return value
but ill tell again now its return "0" that mean no error ,but this its return before its finish the function
So, you can open the file?...opening the file shouldn't take long on a modern system...maybe a few milliseconds. Your for loop is waiting for 30 iterations at 1000ms, so 30 seconds. That's why it's taking so long... so that's your answer.
Looks, like you're programming for a plugin if it's in C#. I assume you know how to program and debug then. So, read the API and get creative. Everytime I've opened a file I just use mcCntlLoadGcodeFile, wait some milliseconds using wxMilliSleep(100), then check for errors and report/break if something went wrong. Works everytime for me.
Can't you have a while loop that checks if there was no error and then maybe read the current gcode file length using mcCntlGetGcodeLineCount and break out of the loop on those conditions? Maybe also close the current gcode file before trying to open a gcode file...not sure if that's necessary but it won't hurt anything...mcCntlCloseGCodeFile.