Async TASK alertDialog wait response ?

Hello all,
i work with visual studio 2015 and xamarin.
i have a project test for sample this project do a for(int i=0; i<=3;i++) and each round download the content of the html page in ASYNC mode
and put the result into a textview ...that's works fine

Now, i would like to add an alertDialog on each round and wait the response of the user but when i do that the method for contiunues WITHOUT wait the response of the alertdialog ...

I'm new to task and i think i'm not understand correctly something ...

here is it the code
`
private async void Button_Click(object sender, EventArgs e)
{
FindViewById(Resource.Id.textView1).Text = "";
await CreateMultipleTasksAsync();
FindViewById(Resource.Id.textView1).Text += "Control returned to startButton_Click.";
}

`

the createMultipleTasksAync
`
async Task CreateMultipleTasksAsync()
{
HttpClient client = new HttpClient() { MaxResponseContentBufferSize = 1000000 };

        int max = 3;
        for (int i = 1; i <= max; i++)
        {
            Task<int> download1 = ProcessURLAsync("http://msdn.microsoft.com", client);
            Task<int> download2 = ProcessURLAsync("http://msdn.microsoft.com/en-us/library/hh156528(VS.110).aspx", client);
            Task<int> download3 = ProcessURLAsync("http://msdn.microsoft.com/en-us/library/67w7t67f.aspx", client);

            // Await each task. 
            int length1 = await download1;
            int length2 = await download2;
            int length3 = await download3;

            // Display the total count for the downloaded websites.
            int total = length1 + length2 + length3;
            FindViewById<TextView>(Resource.Id.textView1).Text += string.Format("\r\n\r\n Start {0} Tour for an total bytes returned:  {1}\r\n", i, total);

            //
            int ret = await displayAlertDialogBox(i);
        }
    }

`

and the alertDialog method

`
async Task displayAlertDialogBox(int loop)
{
int ret = 0;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog dialog = builder.Create();
dialog.SetTitle("ALERT DIALOG");
dialog.SetMessage(string.Format("COUNT {0} ITEM", loop));
dialog.SetCancelable(true);
dialog.SetButton("OK button", (z, ev) =>
{
Toast.MakeText(this, string.Format("Ok button {0}", loop), ToastLength.Long).Show();
ret = 99;
});
dialog.SetButton2("Cancel button", (z, ev) =>
{
Toast.MakeText(this, string.Format("Cancel button {0}", loop), ToastLength.Long).Show();
ret = 1;
});

        //
        dialog.Window.SetGravity(GravityFlags.Center);
        dialog.Show();

        //
        return (ret > 0) ? 1 : 0;
    }

`

my problem is the loop run make the 3 round of downloaded and display 3 times alertDialog WITHOUT waiting the user action

Any idea ?
thanks for your time

Answers

Sign In or Register to comment.