Autor Beitrag
tomycat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: So 20.06.21 16:20 
hallo,
es soll erst die erste HP geladen werden dann die 2te.
Die erste HP enthält Daten die ich für die 2te benötige.

Was muss ich tun dass der 2te Aufruf wartet.
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            Zum_Web symbol_to_ID = new Zum_Web();
            symbol_to_ID.url = "https://ebay.de";
            symbol_to_ID.LoaderAsync();

            Zum_Web new_convert = new Zum_Web();
            new_convert.url = "https://www.msn.com/de-de/";
            new_convert.LoaderAsync();

        }
    }

    internal class Zum_Web
    {
        public String url;
        public String result;

        public async Task<string> LoaderAsync()
        {
            using (var httpClient = new HttpClient())
            result = await httpClient.GetStringAsync(url);
            Console.Write(result);
            return "";
        }
    }
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: So 20.06.21 16:45 
Du benutzt eine asynchrone Methode. Die du mit async auch markiert hast.
Darin hast du bereits das gemacht was du jetzt fragst.

GetStringAsync ist asnychron darum wartest du auf dessen Ende mit await.
Genau das gleiche solltest du dann auch beim Aufruf deiner LoaderAsync Methode machen.

Für diesen Beitrag haben gedankt: tomycat
tomycat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 265
Erhaltene Danke: 1



BeitragVerfasst: So 20.06.21 18:45 
thx,
mir ist das schon klar mit async, aber dann muss ich C# sagen, warten auf den Task und dann warte weiter?!
ich habe einschen gegogelt, bin aber nicht auf eine bessere Lösung gekommen wie...
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
      Zum_Web symbol_to_ID = new Zum_Web();
            symbol_to_ID.url = "https://ebay.de";
            symbol_to_ID.LoaderAsync();
        
            await Task.Delay(5000);

            Zum_Web new_convert = new Zum_Web();
            new_convert.url = "https://www.msn.com/de-de/";
            new_convert.LoaderAsync();
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: So 20.06.21 19:14 
einfach
ausblenden C#-Quelltext
1:
await symbol_to_ID.LoaderAsync();					

Für diesen Beitrag haben gedankt: tomycat
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 21.06.21 08:54 
tomycat, das habe ich dir doch schon in json Datei in C# übers Web integrieren... gezeigt?!

Für diesen Beitrag haben gedankt: tomycat