Thread safe lists - concept

  • Thread starter Thread starter Markus Freitag
  • Start date Start date
M

Markus Freitag

Guest
Hello,

I have a class stacker, this one has 2 lists in it.

The user interface fills in the lists, empties them from the process and reduces them by the entries.
It may happen that the operator fills these, the process reduces this list by one entry.
How do I get the process-proof realized?

Thanks for your tips and examples in advance.

With best regards Markus



More details for understanding.

Step 1 fills TopList
TopList
3, 200
2, 300
1, 500

Is current list empty I move the top list to current list, the last input, is then the first output.

CurrentList (working list)
3, 200
2, 300
1, 500

CurrentList (working list descrease with 50)
3, 150
2, 300
1, 500

CurrentList (working list descrease with 50)
3, 100
2, 300
1, 500

CurrentList (working list descrease with 50)
3, 50
2, 300
1, 500

CurrentList (working list descrease with 50) if <=0 delete the item.
2, 300
1, 500

Is the current list is empty, the top list has entries move top to current list again.


Maybe BlockingCollection<T> ?


public class Stacker
{
public List<PropertyMaterial> ListTop;
public List<PropertyMaterial> ListCurrent;

public Destacker()
{
ListTop = new List<PropertyMaterial>();
ListCurrent = new List<PropertyMaterial>();
}

public class PropertyMaterial
{
public string TypeNo { get; set; }
public int Quantity { get; set; }

//....
//....
//MainWorkflow.cs
if (CurrentStacker.ListCurrent.Count > 0)
{
CurrentDestacker.ListCurrent[0].Quantity = CurrentDestacker.ListCurrent[0].Quantity - 50;
if (CurrentDestacker.ListCurrent[0].Quantity <= 0)
CurrentDestacker.ListCurrent.RemoveAt(0);
}



BlockingCollection<T>
ConcurrentDictionary<TKey,TValue>
ConcurrentQueue<T> Thread First In, First Out (FIFO)
ConcurrentStack<T> Thread Last In, First Out (LIFO)
ConcurrentBag<T>
Picture1376776.jpg
What is right here?
Do I need a thread there?

Continue reading...
 

Similar threads

N
Replies
0
Views
102
Nguyen Duy Hoa -Mr.-
N
M
Replies
0
Views
168
Markus Freitag
M
M
Replies
0
Views
85
Markus Freitag
M
Back
Top