Microsoft.Protocols.TestTools.StackSdk.RemoteDesktop.Rdpedyc.DynamicVirtualChannel.NewChannelId C# (CSharp) Method

NewChannelId() public static method

Get a new unused channel id
public static NewChannelId ( ) : UInt32
return System.UInt32
        public static UInt32 NewChannelId()
        {
            uint newChannelId = 0;
            lock (curChannelIdLock)
            {
                newChannelId = ++CurrentChannelId;
            }
            return newChannelId;
        }

Usage Example

        /// <summary>
        /// Create a dynamic virtual channel
        /// </summary>
        /// <param name="priority">Priority</param>
        /// <param name="channelName">Channel name</param>
        /// <param name="transportType">Transport type</param>
        /// <param name="receiveCallBack">Callback method called when received data</param>
        /// <returns>DVC created</returns>
        public DynamicVirtualChannel CreateChannel(TimeSpan timeout, ushort priority, string channelName, DynamicVC_TransportType transportType, ReceiveData receiveCallBack = null)
        {
            if (!transportDic.ContainsKey(transportType))
            {
                throw new InvalidOperationException("Not create DVC transport:" + transportType);
            }

            UInt32 channelId = DynamicVirtualChannel.NewChannelId();
            DynamicVirtualChannel channel = new DynamicVirtualChannel(channelId, channelName, priority, transportDic[transportType]);

            if (receiveCallBack != null)
            {
                // Add event method here can make sure processing the first DVC data packet
                channel.Received += receiveCallBack;
            }

            channelDicbyId.Add(channelId, channel);

            this.SendDVCCreateRequestPDU(priority, channelId, channelName, transportType);
            CreateRespDvcPdu createResp = this.ExpectDVCCreateResponsePDU(timeout, channelId, transportType);

            if (createResp == null)
            {
                throw new System.IO.IOException("Creation of channel: " + channelName + " failed, cannot receive a Create Response PDU");
            }
            if (createResp.CreationStatus < 0)
            {
                //Create failed
                throw new System.IO.IOException("Creation of DVC failed with error code: " + createResp.CreationStatus + ", channel name is " + channelName);
            }

            return(channel);
        }