Boggo
Boggo
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
im unsure what that means
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
all good, appreciate the time regardless, just threw it in here hoping someone might stumble across it again
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
since thats what the second version is effectively doing
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
ah i had it above actually, i moved it inside to check
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
the http request is the same
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
this will work, just not in order
private async Task DisplayNewMessage(TextMessage message)
{
if (message == null)
{
MessageBox.Show("empty message");
return;
}

var settings = UserSettings.Load();
if (settings.LanguageCode != null)
{
var http = new HttpClient();
var response = await http.GetStringAsync($"myapi");
response = response.Substring(17, response.Length - 19); //removes response information causing error converting to JObject
var translatedMsg = JObject.Parse(response);
var output = translatedMsg["text"]?.ToString();

MessagesLB.Invoke((MethodInvoker)delegate
{
MessagesLB.Items.Add($"{_db.GetClient(message.FromUser).UserName}: {output}");
});
return;
}
MessagesLB.Invoke((MethodInvoker)delegate
{
MessagesLB.Items.Add($"{_db.GetClient(message.FromUser).UserName}: {message.Content}");
});
}
private async Task DisplayNewMessage(TextMessage message)
{
if (message == null)
{
MessageBox.Show("empty message");
return;
}

var settings = UserSettings.Load();
if (settings.LanguageCode != null)
{
var http = new HttpClient();
var response = await http.GetStringAsync($"myapi");
response = response.Substring(17, response.Length - 19); //removes response information causing error converting to JObject
var translatedMsg = JObject.Parse(response);
var output = translatedMsg["text"]?.ToString();

MessagesLB.Invoke((MethodInvoker)delegate
{
MessagesLB.Items.Add($"{_db.GetClient(message.FromUser).UserName}: {output}");
});
return;
}
MessagesLB.Invoke((MethodInvoker)delegate
{
MessagesLB.Items.Add($"{_db.GetClient(message.FromUser).UserName}: {message.Content}");
});
}
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
this does not work
private async Task<List<TextMessage>> TranslateMessages(Stack<TextMessage> messages)
{
var orderedMsgs = new List<TextMessage>();
var settings = UserSettings.Load();


while (messages.Count > 0)
{
var message = messages.Pop();
var http = new HttpClient();
var response = await http.GetStringAsync($"myapi");
response = response.Substring(17, response.Length - 19); //removes response information causing error converting to JObject
var translatedMsg = JObject.Parse(response);
message.Content translatedMsg["text"]?.ToString();
orderedMsgs.Add(message);
}
return orderedMsgs;
}
private async Task<List<TextMessage>> TranslateMessages(Stack<TextMessage> messages)
{
var orderedMsgs = new List<TextMessage>();
var settings = UserSettings.Load();


while (messages.Count > 0)
{
var message = messages.Pop();
var http = new HttpClient();
var response = await http.GetStringAsync($"myapi");
response = response.Substring(17, response.Length - 19); //removes response information causing error converting to JObject
var translatedMsg = JObject.Parse(response);
message.Content translatedMsg["text"]?.ToString();
orderedMsgs.Add(message);
}
return orderedMsgs;
}
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
from within one Task, can i make multiple api requests?
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
hm ok, it was working fine before, with the same api request code
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
winforms
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
trying to use this, once the code hits the await get async part, it stops executing and returns to the UI as it seems
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
until next time
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
well thanks guys, had some input from everyone which was nice :))
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
^^yup
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
which is still true, just very vague
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
that makes a lot of sense, until now void was just "doesnt return anything"
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
i think its a little better now, going to try the sorting thing i had
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
ok i see
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
this here requires private async void
94 replies
CC#
Created by Boggo on 3/15/2023 in #help
❔ multiple Async responses
ty
94 replies