Javascript Hangs When Run Async

Answered
0
0

I need to make an Ajax call to my Azure B2C Tenant to obtain the token.  When run normally using Eval it completes correctly by calling a WebMethod which parses the token.  I’m only in need of the email address in the token for authentication.  I need the script to complete and obtain the email address prior to further authentication inside my vb.net web app.  Running the method as a task using EvalAsync the javascript hangs and never returns the task.  Would you look at my code to see what I’m doing wrong?

Attachment
  • You must to post comments
Best Answer
0
0

Hi Gerald,

The issue is that the task never exists the “WaitingForActivation” state, meaning it hangs trying to finish the task (it gets stuck in the Task queue).
Now the status is not the issue in itself, but rather an indication of why your application hangs.

And that’s because “task.Wait()” is called further up the stack, and that’s what’s causing the deadlock.

What you can do is either.

  • You can just Await the method as you would normally do with an Async function
  • Set a timeout in your Wait method; task.Wait(3000) as an example

I attached a modified version of the test case you provided, in it, you’ll see 3 new Methods – ProcessDataAsync1, ProcessDataAsync2, and ProcessDataAsync3. Each one represents the different approaches you can use to deal with Asynchronous calls.

Promise-style Tasks should always have a timeout, otherwise, the whole application can hang on a single call, that’s why your script works when you use Application.Eval() and hangs with Application.EvalAsync().
HTH,
Alaa

Attachment
  • You must to post comments
0
0

Thanks Alaa!

I used the third suggested method.  I still had some issues trying to obtain the token (email) before the remainder of the internal authentication commenced.  Ultimately, I simply placed the method call for the internal authentication in the Web Method.  That meant the desired email address was obtained prior to internal authentication.

FYI, in the javascript code you updated you added the elements req.setCrossDomain(true); and req.setProhibitCaching(false);.  Initially, the web method would not fire.  On a lark, I commented out these items and it began to work.  I’m not sure what the issue was but I thought I’d give you the feedback.  It works fine now.

Thanks again!

Gerry

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.