nkchandra
nkchandra

Reputation: 5557

Handling Asynchronous operations in Windows Phone7

I am developing a Windows Phone7 application in which I have two App bar buttons both when clicked makes Asynchronous calls to Web and Callbacks will be performed upon the Web response.

Now my problem is, if I click on one button and as the Async operation is going on in the background ans meanwhile if I click on another button both callbacks are executing one after the other, which is not good for obvious reasons. Could any one help me on how to handle this???

First I thought to disable other buttons when 1 Async operation is going. But it doesnt give good feel for user. So what will be the best way to handle this problem??

Upvotes: 0

Views: 287

Answers (2)

MaXi32
MaXi32

Reputation: 668

I was looking for the same answer.

I have found the solution, If you initialize an object inside a constructor like this, you will get multiple loops when you call a service function:

public partial class MainPage : PhoneApplicationPage
{
MovieServiceClient mov;

public MainPage()
{
mov = new MovieServiceClient(); //Don't do this.
InitializeComponent();

}
}

Avoid that.

Upvotes: 0

kanchirk
kanchirk

Reputation: 912

You can use a Flag variable and check its value within the async call complete method. Based on your requirement you can choose to update or not update the view.

Upvotes: 1

Related Questions