public static SessionChannel Create(J2534.Device Device, J2534.Protocol ProtocolID, J2534.Baud Baud, J2534.ConnectFlag Flags) { string Key = $"{Device}:{ProtocolID}:{Baud}"; lock (channelcache) { SessionChannel result; if (!channelcache.ContainsKey(Key)) { var NewChannel = new SessionChannel(Device.GetChannel(ProtocolID, Baud, Flags)); NewChannel.OnDisposing += () => { lock (channelcache) { NewChannel.refCount--; if (NewChannel.refCount < 1) { channelcache.Remove(Key); } } }; channelcache[Key] = NewChannel; } result = channelcache[Key]; result.refCount++; return(result); } }
protected J1979Session(IHeader header, SessionChannel sessionChannel) { this.header = header; this.sessionChannel = sessionChannel; rxQueue = sessionChannel.RxQueue.GetConsumingEnumerable(); rxQueue.BlockingTimeout = 250; }