I need to remove items from the list in a few seconds after adding them. I now have an overview compilation in which I add some messages. I need to remove them, we say that was added after 5 seconds. I tried to create a function responsible for adding items and setting the timer:
Public Zero AddInfoItem (string information) {infoList.Add (info); Timer newtimer = new timer (5000); NewTimer.Elapsed + = New ElapsedEventHandler (this.TimerFunction); NewTimer.Enabled = true; NewTimer.Start (); } Public Zero Timer Function (Object Sender, EventAgds E) {infoList.Clear (); }
I have not sent any parameters, which should be removed because another function has taken exception. Can a person describe the appropriate solution for adding items and after some time to remove it?
This is not a Sory exception to write first
Such collections of views do not support changes to their source collection separately from a thread with a dispatcher thread
If I use DispatcherTimer to work in WPF I usually use something like this I:
public static zero delay (integer milliseconds, action action) {var t = new dispatch timer () {Interval = Timespan From Milliseconds (Milliseconds}} T. Tick + = (O, E) => {T. Stop (); action.Invoke ();}; t.Start ();}
DispatcherTimer will ensure that the event has been applied to the same thread so that you do not run into threading problems. Another option is to secure the collection, but you are actually bound to know that you guess Instead of applying how much an exception you have received, it will be easy.
In addition, if you are quick In many ways, if you add and remove many things, or you need your time to be precise then you should consider something; DispatcherTimer is not very accurate and takes some over, so many examples of it consume some resources.
Comments
Post a Comment