cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to do you stop script execution when using the Scripting API inside a C# app?

Former Member
0 Likes
6,039

I am using the SAP GUI Scripting API 7.10.  My program is written in C#.  I am using the following code (I have removed a lot of code for clarity sake).

SapROTWr.ISapROTWrapper SapROTWrapper = new SapROTWr.CSapROTWrapperClass();

object SapGuilRot = SapROTWrapper.GetROTEntry("SAPGUI");

object engine = SapGuilRot.GetType().InvokeMember("GetScriptingEngine",System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null);

GuiApplication GuiApp = engine as GuiApplication;

GuiConnection connection = GuiApp.Connections.ElementAt(0) as GuiConnection;

GuiSession session = connection.Children.ElementAt(0) as GuiSession;

As soon as the program executes the last statement above, the SAP session indicates via the 'barber pole' that a script is being executed.  Basically, after the above statement my program will look at various text fields and complete it's need for its connection to the SAP scripting engine.  The C# program will continue to run as long as the agent is logged into his/her workstation.  The SAP program will continue to be used by the agent for data entry (they are in a call center).  The 'barder pole' still continues to indicate that a script is being executed.

Is there a way in the SAP GUI Scripting API to stop the 'script' execution?   Basically, my application is not a script and it does not look like the Scripting API was designed to handle this type of application.  The only solution I have discovered so far is to have my program terminate, but this is unacceptable.

Thanks,

Dan

View Entire Topic
Former Member
0 Likes

This is quite an old thread now ... did anyone ever find a resolution ?

My current code is amlost identical to Dan's first post and I am struggling to make sense of how to release the sessions without killing them for the user at the same time.

Any help appreciated!

asdfasdfwef
Newcomer
0 Likes

Late to the party. You need to release the engine object.

Try something like this; in C#.

engine = SapGuilRot.GetType().InvokeMember("GetSCriptingEngine", System.Reflection.BindingFlags.InvokeMethod,null, SapGuilRot, null);

System.Runtime.InteropServices.Marshal.ReleaseComObject(engine);

GC.Collect();

GC.WaitForPendingFinalizers();