Beispiel #1
0
        private int FindValidIndex()
        {
            Dictionary <int, InstanceIndex> procIndex = GetRegisteredDomains();

            FilterValidProcesses(procIndex);
            //所有已使用的索引位。
            List <int> usedIndices = procIndex.Values.Select(ii => ii.Index).ToList();
            int        rtnIndex    = -1;

            for (int i = 1; i <= _maxInstaces; i++)
            {
                if (!usedIndices.Contains(i))
                {
                    rtnIndex = i;
                    break;
                }
            }

            if (rtnIndex > 0)
            {
                procIndex[CurrentBulkId] = new InstanceIndex(rtnIndex, Process.GetCurrentProcess().Id);
                //更新共享内存区。
                UpdateSharedMemory(procIndex);
            }
            return(rtnIndex);
        }
Beispiel #2
0
        private Dictionary <int, InstanceIndex> GetRegisteredDomains()
        {
            Dictionary <int, InstanceIndex> procIndex = new Dictionary <int, InstanceIndex>();

            byte[] data = _bulk.ReadSharedData();
            int    pos  = 0;

            for (int i = 0; i < _maxInstaces; i++)
            {
                int bulkId = getIntFromBytes(data, ref pos);
                if (bulkId <= 0)
                {
                    break;
                }
                int index     = getIntFromBytes(data, ref pos);
                int processId = getIntFromBytes(data, ref pos);
                procIndex[bulkId] = new InstanceIndex(index, processId);
            }
            return(procIndex);
        }