-1

I have tried looking into the How to call any method asynchronously in c# question but it fails to answer by query so let me ask it anyway.

I am accessing a web refence in my code which basically calls a function called ExportDataset.

DataSet dsUsers = serviceOws.ExportDatasetAsync("test012", "<parameters></parameters>");

The problem with this bit is it takes about 30 seconds to fetch the records. I cannot change the web reference code at all as i dont have access. My page doesn't load at all whilst this happens.

Is there any way to call this function asyncrounously whilst my page loads? My project targets .NET framework 4.6.1

4
  • 1
    Your... . page? Commented Oct 26, 2018 at 11:51
  • What page? Where does that code run? What framework? We need much more details. Commented Oct 26, 2018 at 11:54
  • yes, webpage if you want to get down to brass tacks Commented Oct 26, 2018 at 11:54
  • Assuming you're talking about a web app, you cannot return the response until all your async operations are complete unless you fire-and-forget which would be pointless in your case. You could code the page to do a client-side ajax request. You'd have to provide another endpoint to do the actual service call because obviously you can't use the service reference in the client browser. Commented Oct 26, 2018 at 11:55

1 Answer 1

2

You can wrap synchronous calls in a Task by using Task t = new Task(() => MyLongRunningOperation()), but that won't get your page rendering faster because it's still going to wait for that task to finish before sending the page content. You will need to expose this call in a separate API or something else and load it via AJAX if you really want a long running operation like this to work "seamlessley".

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

2 Comments

thanks. Yeah. I guess i will have to use AJAX. Just thought there might be a smarter way of doing it. Thanks for you help. Points me in the right direction. Definitely much more helpful than smart ass comments from keyboard warriors
Unfortunately I don't know of a framework that can automagically tie up an asynchronous operation render asynchronously as well on the client side.

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.