开发者

C# Convoyor-Belt-like buffer - Time constrained buffer

开发者 https://www.devze.com 2022-12-21 15:59 出处:网络
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开发者_如何

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.
0

精彩评论

暂无评论...
验证码 换一张
取 消