I'd like to program a buffer that is time constrained. It means that I want to be able to continuously fill up a List of string (for instance) and every 2 secondes that list is added to ano开发者_如何转开发ther list (or send to the network) whether this list has 1 or more elements, but another List of string take its place so that there are always a List of string being filled up.
How can I do that in C# ?
You can do that in C# by using a combination of
- the generic List<T> collection class,
- a Timer to execute a method at regular intervals in a worker thread, and
- a lock statement to synchronize access to a resource shared by threads.
精彩评论