I have a Dictionary that is Dictionary<int, RSendPacket>
_Packets and there are two main threads. Thread #1 adding packets with this function
public void EnqueueOutgoingData(int id, byte[] data)
{
RSendPacket packet = new RSendPacket(data);
_Packets.Add(id, packet);
}
The Thread #2 is reads and sends the packet via socket like this
private void _Process(RSendPacket packet)
{
foreach (KeyValuePair<int, RSendPacket> o in _Packets)
{
//Socket send (o.Value >> That's RSendPacket class)
}
}
at this point, I'm getting an error. I'm adding "asdf" but it carries it as "► o". It is a threading/memory error I think but I cant fix it because I don't know how! Can anybody help me about this? (I can implement a system in C++ with pointers and memory management and it should be a memory management problem -caused by my bad c#)
EDIT1: And yes there isn't a thread-safe implemention but I've tried it with 'lock()' and not works!
EDIT2: Oh another important edit. I'm using C# 2.0 with Unity. So solution should be a C# 2.0 (mono) code :/