locked
Async await screen change runtime

    Pregunta

  • The code snippet below shows a window with a button "Asynchronous execution", where I click on it appears to me, "Getting data ..." this asynchronously, the problem is that my application is web browser works and working with different medium.

    The client server communication exists only after the page is fully loaded ie the resulting data does not appear, so it appears the download url of what was done, leaving the user aware of what is happening.

    How do I talk to the client before the page is fully loaded?

     

            private async void ObterDadosAsync(WebClient w)
            {
                string texto = await w.DownloadStringTaskAsync("http://www.devmedia.com.br/");
                textBlock1.Text = texto;
            }
            private void btDownSincrono_Click(object sender, RoutedEventArgs e)
            {
                textBlock1.Text = "Getting data ...";
                WebClient w = new WebClient();
                ObterDados(w);
            }

    miércoles, 15 de febrero de 2012 13:13

Respuestas

  • As Paulo says, it must be asynchronous. You can use any supported script language to trigger the postback without user action but did you need to code these client-script? The answer is no. You can easily use the System.Web.UI.Timer control and it will trigger the postback for you.

    Now, regarding you async task execution problem, you should encapsulate your async task using the System.Web.UI.PageAsyncTask and then use the Page.RegisterAsyncTask method.

    Alone these 2 technics won't solve your problem but if you use both you will get periodic pooling until async task end successfully.


    Nuno Gomes http://nunogomes.net

    viernes, 17 de febrero de 2012 2:10

Todas las respuestas

  • If the code you are showing is ASP.NET runtime code, then the asynchronous operation is running on the server as part of a synchronous client call.

    The benefit here is that the thread handling the request (the ASP.NET "UI thread") is returned to the request handling thread pool and can be used to service other client requests.

    If you want your code to be asynchronous in the client, you'll have to use AJAX (the first A is for asynchronous).


    Paulo Morgado

    miércoles, 15 de febrero de 2012 16:12
  • There is another way that i can do that without use a AJAX call?

    • Propuesto como respuesta gandalfne0 miércoles, 15 de febrero de 2012 17:08
    • Votado como útil gandalfne0 miércoles, 15 de febrero de 2012 17:09
    miércoles, 15 de febrero de 2012 16:59
  • You can call it whatever you want to (:)), but want you want to happen is on the browser and needs to be done on the browser. Thus, JScript.

    Paulo Morgado

    miércoles, 15 de febrero de 2012 23:03
  •  i still trying without any success, u can show me a example for i see how can i do this? Cuz until now every tentative that i try, result at the same thing, my msg always show at the ende of request, never while requesting.

    jueves, 16 de febrero de 2012 12:15
  • This is not a forum for JScript, but can you show the JScript code you're using?


    Paulo Morgado

    viernes, 17 de febrero de 2012 0:02
  • As Paulo says, it must be asynchronous. You can use any supported script language to trigger the postback without user action but did you need to code these client-script? The answer is no. You can easily use the System.Web.UI.Timer control and it will trigger the postback for you.

    Now, regarding you async task execution problem, you should encapsulate your async task using the System.Web.UI.PageAsyncTask and then use the Page.RegisterAsyncTask method.

    Alone these 2 technics won't solve your problem but if you use both you will get periodic pooling until async task end successfully.


    Nuno Gomes http://nunogomes.net

    viernes, 17 de febrero de 2012 2:10
  • Thankz Nuno, your explanation clear some of my ideas, but i have one more question.

    In my app, i have 2 textbox, 1 label, 2 button(Async, Sync), the first one button should be execute your async task, and while the async task is requesting, i will click on the Sync button, and i want that my Async button doesnt stop his request. If's that possible to make up using System.Web.UI.PageAsyncTask and Page.RegisterAsyncTask , as you say?

    and if so, can you tell me how to do?

    thnkz

    viernes, 17 de febrero de 2012 10:34