-1

at first I'd like to tell you what's my aim: I'd like to build a threadsafe list. (I can't use a Queue because afaik we should only use a Queue for FIFO) This list should be filled In one thread and in the other thread I'd like to work it off. With working off I mean, that I'd like to always analyze all the entries of the list and sort them against a specific Int-value. Then I'd like to do something with the "most important" entry of the list and so on...

Thank you!

xileb0
  • 401
  • 4
  • 17
  • What you have described sounds like not a list, but queue with priority. – Yeldar Kurmangaliyev Nov 06 '15 at 08:36
  • Thank you Yeldar, is something like that avaliable in the Framework? Or do I have to build my own? – xileb0 Nov 06 '15 at 08:39
  • 1
    It looks like there is no such data structure in .NET. You can implement it yourself (maybe, with the help of existent Thread-Safe Collections) or find the solution in the Internet. For example, I have found this on Google: https://github.com/dshulepov/ConcurrentPriorityQueue. However, I am not sure if it works or suitable :) If it works - let me know so that I can write it as an answer. – Yeldar Kurmangaliyev Nov 06 '15 at 08:43
  • Yeldar, I implemented something similar to that. I used this one: https://github.com/BlueRaja/High-Speed-Priority-Queue-for-C-Sharp It is absolutely easy to use and works great. Thank you for your hint! You can write it as an answer. :) – xileb0 Nov 10 '15 at 15:31

1 Answers1

0

Instead of re-inventing the wheel (which you can if you want), and given that you seems to need a thread safe LIFO system, I recommend you to use the ConcurrentStack Class

Thomas Ayoub
  • 27,208
  • 15
  • 85
  • 130