0

I am connnecting to an API and using an Async library (Koenzomers) when I run this from a console app, it works absolutely fine, when I run it from a asp.net webform page I can't get it to work.

Code I have

if I try to run the task as I run from the console app

                    Task TestAuth = TestOtherLibrary();
                    TestAuth.Wait();

I get the same result.

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("Authenticating");
    RegisterAsyncTask(new PageAsyncTask(Auth));
}

public async Task Auth()
{
    using (KoenZomers.UniFi.Api.Api UnifiApp = new KoenZomers.UniFi.Api.Api(new System.Uri("https://myserverurl"), "unifisiteid"))
    {
    await UnifiApp.Authenticate("admin", "mysecurepassword");

    }
}

The idea is to connect to the unifi controller and authorize user based on mac address

Currently, I get the page loading in a deadlock, not sure if the UI is waiting for the task to end, and it never ends.

2

1 Answer 1

0

Instead of using PageAsyncTask, Use the below one,

var localVariable = Task.Run(async () => await Auth())?.Result;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.