title: AsyncTasks and ProgressDialogs
body: <p>I need to build BaseExpandableListAdapters using lists of data from the server.  I am using an AsyncTask to retreive this list of values.  As I cannot currently return a BaseExpandableListAdapter from the DoInBackGround override method, I am using public properties.  With below code I can either:</p>
  
  <ol>
  <li>Get the My and Market properties of my AsyncTask class to return with all expected values BUT my ProgressDialog doesn't appear until after the task is executed rendering it useless, OR</li>
  <li>Get the ProgressDialog to show up immediately as desired BUT the My and Market properties are empty when I try to use them to assign adapters to my listviews</li>
  </ol>
  
  <p>I need to achieve both.</p>
  
  <pre><code>public class Work : Activity
  {
      private ExpandableListView market;
      private ExpandableListView my;
  
      protected override void OnCreate(Bundle bundle)
      {
          base.OnCreate(bundle);
  
          SetContentView(Resource.Layout.Work);
  
          market = (ExpandableListView)FindViewById(Resource.Id.market);
          my = (ExpandableListView)FindViewById(Resource.Id.my);
  
          PopulateWorkListViews populate = new PopulateWorkListViews(this);
          populate.Execute(techID, market, userType);
  
          //Removing the following line allows for the ProgressDialog but the Market 
          //and My properties of the PopulateWorkListViews class are empty as opposed 
          //to leaving this line in and both properties contain all expected values 
          //but ProgressDialog doesn't show up.
          string result = populate.Get().ToString();
  
          market.SetAdapter(populate.Market);
          my.SetAdapter(populate.My);
      }
  }
  
  public class PopulateWorkListViews : AsyncTask
  {
      private Context Context { get; set; }
      private ProgressDialog Dialog { get; set; }
      public BaseExpandableListAdapter Market { get; set; }
      public BaseExpandableListAdapter My { get; set; }
  
      public PopulateWorkListViews(Context context)
      {
          Context = context;
      }
  
      protected override void OnPreExecute()
      {
          Dialog = new ProgressDialog(Context);
          Dialog.SetMessage("Processing...");
          Dialog.Window.SetGravity(GravityFlags.Center);
          Dialog.SetCancelable(false);
          Dialog.Indeterminate = true;
          Dialog.SetProgressStyle(ProgressDialogStyle.Spinner);
          Dialog.Show();
      }
  
      protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
      {
          WS ws = new WS();
          List&lt;ServiceCall&gt; calls = ws.GetMarketCalls(@params[0].ToString(), @params[1].ToString(), @params[2].ToString()).ToList();
  
          Market = new MarketCallListView(Context, calls);
          My = new MyCallListView(Context, calls, @params[0].ToString());
  
          return "Done";
      }
  
      protected override void OnPostExecute(Java.Lang.Object result)
      {
          Dialog.Dismiss();
      }
  }
  </code></pre>