Reputation: 63
I want to log into a listbox in uwp from another thread.
I know from windows forms that i should use delegates. But their are no invoke methods. This is my interface i use for logging. And that was the first thing i tried to use.
public interface ILoggingService
{
void LogInformation(LogEntryType logEntryType,string logEntryMessage);
}
delegate void LoggerDelegate(LogEntryType logEntryType,string message);
LoggerDelegate _loggerDelegate = new LoggerDelegate(LogInformation);
public void LogInformation(LogEntryType logEntryType,string logEntryMessage)
{
if (lbxInformation.InvokeRequired)
{
lbxRequestInformation.Invoke(logRequestInformationDelegate,message);
}
else
{
lbxInformation.Items.Add(message);
}
}
Upvotes: 0
Views: 158
Reputation: 13850
Use Dispatcher.RunAsync to update the UI from another thread. Here is the documentation:
Upvotes: 1