Asynchronous operation exception if I want to create an instance of a class

918 views Asked by At

I am currently working on a big asp.net page, created by a lot of other developers, used by a lot of people internally. I got a rather simple task to modify the page, for that I had to create a class and added the DLL to the bin folder.

VoiceChecker vr = new VoiceChecker();

throws the following exception:

Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.

Why is this an asynchronous operation? I don't want it to be asynchronous, I actually want the page to wait for that operation to finish. I've tried to set the @Page to Async=true, but for some reason it just blocks the page endlessly, even though my code should be done in <1s.

How can I make my class synchronous?

1

There are 1 answers

0
woz On

Declaring a new object will not trigger this error unless the constructor contains asynchronous code.