Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

An asynchronous operation cannot be started at this time error

$
0
0

When I try to call WCF Service asynchronously from my web application after button click, I get this error:

[InvalidOperationException: An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the Page is marked <%@ Page Async="true" %>.]

Code

 protected async void btnStartPrintJob_Click(object sender, EventArgs e) {
            await RunPrintJOB();
        }


 private async Task<int> RunPrintJOB() {
            PdfService.ServiceClient client = null;
            int value = 0;
            try {
                client = new PdfService.ServiceClient();
                string destination = Setting.Temp + Guid.NewGuid() + ".pdf";
                if (jobFileUpload.HasFile) {
                    value = await client.RunPrintJobAsync(new MemoryStream(jobFileUpload.FileBytes), destination);
                }


            } catch (Exception ex) {

            } finally {
                client.Close();
            }

            return value;
        }
Please can someone help me fix this.
Thanks


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>