Tech Off Post

Single Post Permalink

View Thread: Parallel Tasks
  • User profile image
    LotharV

    Yes I know what you mean but that is not what i want to do.

    I'll add some comments to make it a bit more clear.

    case Type.First:
        //this can just run
                      s = await client.GetStringAsync("http://nl" + WorldName + ".tribalwars.nl/map/ally.txt");
                      s = s.Replace("\n", ",");
                      sSplit = s.Split(',');
                      for (int i = 0; i < s.Length; i += 7)
                      {
                            Allies.Add(new Ally(sSplit[i], sSplit[i + 1], sSplit[i + 2], sSplit[i + 3], sSplit[i + 4], sSplit[i + 5], sSplit[i + 6], sSplit[i + 7]));
                      }
                      bAlly = true;
                      break;
    case Type.Second:
    //this can just run
                      s = await client.GetStringAsync("http://nl" + WorldName + ".tribalwars.nl/map/player.txt");
                      s = s.Replace("\n", ",");
                      sSplit = s.Split(',');
    //this has to wait foor the first method to have finished. The above can run before the first method has finished.
                      while (!bAlly)
                      {
                            await Task.Delay(100);
                      }
                      for (int i = 0; i < s.Length; i += 7)
                      {
                            Players.Add(new Player(sSplit[i], sSplit[i + 1], sSplit[i + 2], sSplit[i + 3], sSplit[i + 4], sSplit[i + 5]));
                      }
                      bPlayer = true;
                      break;
    

    So the first method and the beginning of the second method can run simultaneous. The end of the second method has to wait for the first method to be finished.