cancel
Showing results for 
Search instead for 
Did you mean: 

Proper async and await .Net Language Keyword Support

Not applicable

Is there any plans to add proper async and await keyword support in OnBase studio? Currently, one can include those keywords and compile properly but the await keyword doesn't get acted upon, and the thread just continues, and when the Script context exits any async work still in progress halts.


Or better yet, is there a way to have a class that implements IWorkflowScript (or any of the other Unity interfaces) inside an DLL and have those classes exposed for usage inside a workflow configuration?

1 ACCEPTED ANSWER

Chris_Tucker
Star Contributor
Star Contributor

Hi Luis,

Async/await is supported in Unity scripts. However, the script framework will not await the OnExecute method if you configure it as async. This means that the script will "finish" execution before the code in it has completed running. This could cause unpredictable behavior and is likely to produce errors, so I strongly recommend that you do not mark your OnExecute method as async. Instead, call Wait() or Result on the task returned by your async method to ensure that all code has completed before the script finishes execution.

To your second question, you cannot write an external assembly which implements a script interface, but you can call external assemblies from inside of a script. Just write your assembly in Visual Studio, import it into OnBase Studio, and add a reference to it in your script.

Hope this helps!

View answer in original post

4 REPLIES 4

Chris_Tucker
Star Contributor
Star Contributor

Hi Luis,

Async/await is supported in Unity scripts. However, the script framework will not await the OnExecute method if you configure it as async. This means that the script will "finish" execution before the code in it has completed running. This could cause unpredictable behavior and is likely to produce errors, so I strongly recommend that you do not mark your OnExecute method as async. Instead, call Wait() or Result on the task returned by your async method to ensure that all code has completed before the script finishes execution.

To your second question, you cannot write an external assembly which implements a script interface, but you can call external assemblies from inside of a script. Just write your assembly in Visual Studio, import it into OnBase Studio, and add a reference to it in your script.

Hope this helps!

I understand that it compiles and runs, but is there a reason why the script framework does not support awaiting? By using Wait() or Result then the execution goes back to simply being a synchronous and blocks the thread which defeats the whole purpose of building an asynchronous library.

Is there any plan to add make the script framework "await aware"?

The script framework can't await the OnExecute method because it executes scripts as their interface type. For example, when we execute a workflow script we call IWorkflowScript.OnWorkflowScriptExecute. Since IWorkflowScript doesn't define OnWorkflowScriptExecute as an async method, we cannot await it, even if your script implementation does define it as an async method. In order to make the framework await aware, we would need to create new script interface types with async method signatures.

That being said, it is possible to create asynchronous scripts. Marking the OnWorkflowScriptExecute method as async will cause the script framework to fire and forget your script. Control will immediately return back to the client, and your script will continue executing. I'd be very cautious about doing this though. Any exceptions thrown will not be reported, and use of the Application object or other API objects may not function as expected. You could also achieve this behavior by performing your work in a seperate thread. If you just want the internals of your script to be asynchronous, you can use async/await everywhere except for the OnExecute method, where you'd have to use Wait/Result. As you mentioned this would cause the client/app server thread executing the script to be blocked until the script completes execution. However, it wouldn't be any different than if the script framework awaited your OnExecute method.

I hope this makes sense. Let me know if you have any more questions!

In last week's blog post, the API team touched on this topic:

"In order to isolate them from the rest of OnBase, all Unity Scripts execute in a scripting app domain. However, we do not make any guarantees about the lifetime or behavior of the scripting app domain."

They didn't specifically address your question about asynchronous execution, but it seems clear that the system was not designed to support custom code running at arbitrary times. Your asynchronous solution may not work as intended, and the behavior may be inconsistent at different times or after an upgrade.