views:

34

answers:

1

Hello,

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 another 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# ?

+1  A: 

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.
dtb
Thanks. I tried that but it didn't work. The clue was to execute my main thread outside the timer thread.
Guillaume