cancel
Showing results for 
Search instead for 
Did you mean: 

Invoking a global async method in code stage

SRashidi
Level 3

Hello,

I developed an async method in my Blue Prism object's initial page (global code):

 static async Task<string> GetAuthenticationResponseAsync()
    {
       ...
    }

 

The method returns a string value.

Now, I need to invoke this method in the Blue Prism's code stage. How can I invoke an async method in the Blue Prism code stage?

I've tried this:

string responseData = await GetAuthenticationResponseAsync();

however, the compiler is complaining:

The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.

I also tried:

responseData = GetAuthenticationResponseAsync().GetAwaiter().GetResult();

This resolved the compiler error, however, when I run the action (code stage), Blue Prism is permanently stuck on the code stage, and I have no option but to terminate Blue Prism via task manager.

Is there a way that I could invoke the async method through the code stage?

Thanks!



------------------------------
S Rashidi
------------------------------
2 REPLIES 2

bclayton1896
Level 4

Does this link to a previous thread help you any? It looks like there is an Output() method at the end of the suggested code.

https://community.blueprism.com/communities/community-home/digestviewer/viewthread?GroupId=145&MessageKey=65e30866-3e45-4a56-845d-f77e2d3986ec&CommunityKey=3743dbaa-6766-4a4d-b7ed-9a98b6b1dd01?utm_sou...



------------------------------
Brian Clayton
Applications Consultant
The Auto Club Group
America/Dearborn MI
313-336-1896
------------------------------

smssubhani
Level 3

For Async function

Here is the best solution for BP code stage I got implemented.

var result = Task.Run(async () => await GetAccessToken()).Result;



------------------------------
Mahaboobsubani Shaik
------------------------------