Answer the question
In order to leave comments, you need to log in
How to add elements to a collection once per second?
I have a collection:
public ViewModelCollection<ReceivedApplicationMessageViewModel> ReceivedApplicationMessages { get; } = new ();
public ViewModelCollection<ReceivedApplicationMessageViewModel> ReceivedApplicationMessagesChunk { get; } = new();
public ViewModelCollection<ReceivedApplicationMessageViewModel> ReceivedApplicationMessages { get; } = new ();
public ViewModelCollection<ReceivedApplicationMessageViewModel> ReceivedApplicationMessagesChunk { get; } = new();
public Task HandleApplicationMessageReceivedAsync( MqttApplicationMessageReceivedEventArgs eventArgs )
{
return Dispatcher.UIThread.InvokeAsync( () =>
{
ChunkMessages( eventArgs.ApplicationMessage );
} );
}
private void ChunkMessages( MqttApplicationMessage applicationMessage )
{
ReceivedApplicationMessagesChunk.Insert( 0, new ReceivedApplicationMessageViewModel(
_messageId++,
applicationMessage ) );
ReceivedApplicationMessages.AddRange( ReceivedApplicationMessagesChunk );
ReceivedApplicationMessagesChunk.Clear();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question