public int Add(UlTcInstruction inst, long waiting = 1000) { Stopwatch sw = new Stopwatch(); if (instructs.Count >= instLength) { throw new Exception("Instruction counter overflow error in UlTcFunction::Add"); } sw.Start(); while (ContainsIndex(inst.Index) == true) { if (sw.ElapsedMilliseconds > waiting) { throw new Exception("Duplicated instruction index error in UlTcFunction::Add"); } Thread.Sleep(1); } inst.Handle = rndHandle.Next(); lock (dataLock) { instructs.Add(inst.Handle, inst); } return(inst.Handle); }
public UlTcProcedure(string name, UlTcAdsClient client, int length = 16) { this.name = name; this.client = client; this.instLength = length; dataLock = new object(); rndHandle = new Random(); inst = new UlTcInstruction(); instructs = new Dictionary <int, UlTcInstruction>(); }
public UlTcInstruction GetInstruction(int handle) { ContainsHandle(handle); UlTcInstruction inst; lock (dataLock) { inst = instructs[handle]; } return(inst); }