• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Channel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Channel的典型用法代码示例。如果您正苦于以下问题:C# Channel类的具体用法?C# Channel怎么用?C# Channel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Channel类属于命名空间,在下文中一共展示了Channel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: can_read_after_select_on_queued_Channels

 public void can_read_after_select_on_queued_Channels()
 {
     var ch1 = new Channel<int>(1);
     var ch2 = new Channel<bool>(1);
     ThreadPool.QueueUserWorkItem(state => {
         ch1.Send(123);
         ch2.Send(true);
         ch2.Close();
         ch1.Send(124);
         ch1.Close();
     });
     using (var select = new Channels(Op.Recv(ch1), Op.Recv(ch2))) {
         var got = select.Select();
         Debug.Print("got.Index = " + got.Index);
         if (got.Index == 0) {
             Assert.AreEqual(123, got.Value, "got.Value");
             Assert.AreEqual(Maybe<bool>.Some(true), ch2.Recv());
         }
         else {
             Assert.AreEqual(1, got.Index, "got.Index");
             Assert.AreEqual(true, got.Value, "got.Value");
             Assert.AreEqual(Maybe<int>.Some(123), ch1.Recv());
         }
         select.ClearAt(1);
         got = select.Select();
         Assert.AreEqual(0, got.Index, "got.Index, value =" + got.Value);
         Assert.AreEqual(124, got.Value, "got.Value");
     }
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:29,代码来源:SelectTests.cs


示例2: Main

        static void Main(string[] args)
        {
            Channel channel = new Channel();
            HelloService service = new HelloService();
            channel.AddMethod<HelloRequest, HelloSerializer>("maid.example.HelloService.HelloNotify", service.HelloNotify);
            channel.AddMethod<HelloRequest, HelloSerializer, HelloResponse, HelloSerializer>("maid.example.HelloService.HelloRpc", service.HelloRpc);
            channel.ConnectedCallback.Add(() =>
            {
                Console.WriteLine("连接上了");
            });

            channel.Connect("192.168.0.99", 8888);

            while (true)
            {
                channel.Update();

                HelloRequest request = new HelloRequest();
                request.message = "this message from protobuf-net";
                try
                {
                    channel.CallMethod("maid.example.HelloService.HelloNotify", request);
                    channel.CallMethod("maid.example.HelloService.HelloRpc", request);
                }
                catch (Exception ){ }
                if (channel.Connecting)
                {
                    Console.WriteLine("连接中");
                }
            }
        }
开发者ID:rayx999,项目名称:libmaid,代码行数:31,代码来源:Program.cs


示例3: can_recv_one_item_before_closing

 public void can_recv_one_item_before_closing()
 {
     var ch = new Channel<int>(1);
     ThreadPool.QueueUserWorkItem(state => { ch.Send(123); ch.Close(); });
     Assert.AreEqual(Maybe<int>.Some(123), ch.Recv());
     Assert.AreEqual(Maybe<int>.None(), ch.TryRecv());
 }
开发者ID:busterwood,项目名称:NetChan,代码行数:7,代码来源:QueuedChannelTests.cs


示例4: BatchingWithKey

        public void BatchingWithKey()
        {
            using (var fiber = new ThreadFiber())
            {
                fiber.Start();
                var counter = new Channel<int>();
                var reset = new ManualResetEvent(false);
                Action<IDictionary<String, int>> cb = delegate(IDictionary<String, int> batch)
                {
                    if (batch.ContainsKey("9"))
                    {
                        reset.Set();
                    }
                };

                Converter<int, String> keyResolver = x => x.ToString();
                counter.SubscribeToKeyedBatch<int, String>(fiber, cb, keyResolver, 0);

                for (var i = 0; i < 10; i++)
                {
                    counter.Publish(i);
                }

                Assert.IsTrue(reset.WaitOne(10000, false));
            }
        }
开发者ID:GWBasic,项目名称:retlang,代码行数:26,代码来源:BasicExamples.cs


示例5: CommandContext

        public CommandContext(Client irc, UserCollection users, User from, Channel channel, string message)
        {
            this._irc = irc;
            this._users = users;

            this.From = from;
            this._channel = channel;

            if (message[0] == '!' || message[0] == '.')
            {
                this._replyNotice = true;
            }
            else
            {
                this._replyNotice = false;
            }

            if (message[0] == '!' || message[0] == '.' || message[0] == '@')
            {
                this.Message = message.Substring(1);
            }
            else
            {
                this.Message = message;
            }
        }
开发者ID:alfaproject,项目名称:Supay-Bot,代码行数:26,代码来源:CommandContext.cs


示例6: ChatServerMessage

 public ChatServerMessage(Channel chan, string message, Global.Character actor)
     : base(PacketType.ChatServerMessage)
 {
     Channel = chan;
     Message = message;
     Actor = actor;
 }
开发者ID:Emudofus,项目名称:Aldos,代码行数:7,代码来源:ChatServerMessage.cs


示例7: Init

 public override void Init(Channel ch, ProtocolHeader hdr)
 {
     if (hdr.Major != 0 && hdr.Minor != 10)
     {
         throw new ProtocolVersionException((sbyte) hdr.Major, (sbyte) hdr.Minor);
     }
 }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:7,代码来源:ClientDelegate.cs


示例8: GetMillivolts

        public double GetMillivolts(Channel channel, Gain gain = Gain.Volt5, SamplesPerSecond sps = SamplesPerSecond.SPS1600) {
            lock (deviceLock) {

                byte[] result = new byte[2];

                // Set disable comparator and set "single shot" mode	
                config = 0x0003 | 0x8000; // | 0x100;
                config |= (ushort)SamplePerSecondMap[(int)sps];
                config |= (ushort)channel;
                config |= (ushort)programmableGainMap[(int)gain];

                data[0] = REG_CFG;
                data[1] = (byte)((config >> 8) & 0xFF);
                data[2] = (byte)(config & 0xFF);


                I2CDevice.Write(data);
                // delay in milliseconds
                //int delay = (1000.0 / SamplesPerSecondRate[(int)sps] + .1;
            //    int delay = 1;
                Task.Delay(TimeSpan.FromMilliseconds(.5)).Wait();

                I2CDevice.WriteRead(new byte[] { (byte)REG_CONV, 0x00 }, result);

                //var r = (((result[0] << 8) | result[1]) >> 4);

                //Debug.WriteLine(r.ToString());

                return (ushort)(((result[0] << 8) | result[1]) >> 4) * programmableGain_Scaler[(int)gain] / 2048;
            }
        }
开发者ID:StephanieMak,项目名称:IoT-Maker-Den-Windows-for-IoT,代码行数:31,代码来源:ADS1015.cs


示例9: _AddChannel

 private void _AddChannel(Channel channel)
 {
     ChannelColorStateControl control = new ChannelColorStateControl(channel.Name);
     _channelControls[channel.Id] = control;
     control.Dock = DockStyle.Top;
     Controls.Add(control);
 }
开发者ID:kjburns31,项目名称:vixen-modules,代码行数:7,代码来源:TestPreviewForm.cs


示例10: Start

        public void Start(Channel channel, int numWorkerThreads)
        {
            channelReceiver = channelFactory.GetReceiver(channel.Type);

            channelReceiver.DataReceived += DataReceivedOnChannel;
            channelReceiver.Start(channel.Address,numWorkerThreads);
        }
开发者ID:rsummer,项目名称:NServiceBus,代码行数:7,代码来源:IdempotentChannelReceiver.cs


示例11: YPitchBendCube

        public YPitchBendCube(Point3D center, double radius, 
                Pitch pitch, Instrument instrument, OutputDevice device, Channel channel)
            : base(center, radius, new InstrumentNoteAction(device, channel, pitch)) {

                outputDevice = device;
                this.channel = channel;
        }
开发者ID:probuilderz,项目名称:balloon,代码行数:7,代码来源:YPitchBendCube.cs


示例12: ProtocolFaultResponseException

		/// <summary>
		/// Initializes a new instance of the <see cref="ProtocolFaultResponseException"/> class
		/// such that it can be sent as a protocol message response to a remote caller.
		/// </summary>
		/// <param name="channel">The channel to use when encoding the response message.</param>
		/// <param name="errorResponse">The message to send back to the HTTP client.</param>
		/// <param name="faultedMessage">The message that was the cause of the exception.  May be null.</param>
		/// <param name="innerException">The inner exception.</param>
		/// <param name="message">The message for the exception.</param>
		protected internal ProtocolFaultResponseException(Channel channel, IDirectResponseProtocolMessage errorResponse, IProtocolMessage faultedMessage = null, Exception innerException = null, string message = null)
			: base(message ?? (innerException != null ? innerException.Message : null), faultedMessage, innerException) {
			Requires.NotNull(channel, "channel");
			Requires.NotNull(errorResponse, "errorResponse");
			this.channel = channel;
			this.ErrorResponseMessage = errorResponse;
		}
开发者ID:437072341,项目名称:dotnetopenid,代码行数:16,代码来源:ProtocolFaultResponseException.cs


示例13: AttemptToCloseChannel

 protected void AttemptToCloseChannel(Channel channel)
 {
     if (channel.UserCount == 0
         && channel != Channel_Main
         && channel != Channel_Void)
         Channels.Remove(channel);
 }
开发者ID:AlphaBlend,项目名称:VNet,代码行数:7,代码来源:ChannelFunctions.cs


示例14: Start

        public void Start(Channel channel)
        {
            channelReceiver = (IChannelReceiver)builder.Build(channel.Receiver);

            channelReceiver.DataReceived += DataReceivedOnChannel;
            channelReceiver.Start(channel.ReceiveAddress, channel.NumWorkerThreads);
        }
开发者ID:davidalpert,项目名称:NServiceBus,代码行数:7,代码来源:IdempotentReceiver.cs


示例15: Hook_PRIV

 public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message)
 {
     if (message.StartsWith(Configuration.System.CommandPrefix + "translate "))
     {
         message = message.Substring(11);
         List<string> parts = new List<string>(message.Split(' '));
         if (parts.Count < 3)
         {
             IRC.DeliverMessage("Invalid number of parameters", channel);
             return;
         }
         string target = null;
         string source_language = parts[0];
         string target_language = parts[1];
         if (!IsValid(source_language) || !IsValid(target_language))
         {
             IRC.DeliverMessage(invoker.Nick + ": invalid language!", channel);
             return;
         }
         string text = message.Substring(message.IndexOf(parts[1]) + parts[1].Length + 1);
         if (text.Contains("|"))
         {
             target = text.Substring(text.IndexOf("|") + 1).Trim();
             text = text.Substring(0, text.IndexOf("|"));
         }
         // schedule a message
         Ring.Add(new Buffer.Item(channel, source_language, target_language, target, text));
     }
 }
开发者ID:reviforks,项目名称:wikimedia-bot,代码行数:29,代码来源:Translate.cs


示例16: Extension_DumpHtml

 public override string Extension_DumpHtml(Channel channel)
 {
     string HTML = "";
     DebugLog("Getting html for " + channel.Name);
     try
     {
         if (GetConfig(channel, "RC.Enabled", false))
         {
             RecentChanges rc = (RecentChanges)channel.RetrieveObject("RC");
             if (rc != null)
             {
                 HTML = rc.ToTable();
             }
             else
             {
                 Syslog.ErrorLog("NULL rc for " + channel.Name);
             }
         }
         else
         {
             DebugLog("RC is disabled for " + channel.Name, 2);
         }
     }
     catch (Exception fail)
     {
         HandleException(fail);
     }
     return HTML;
 }
开发者ID:benapetr,项目名称:wikimedia-bot,代码行数:29,代码来源:ModuleRC.cs


示例17: RegisterExtension

        internal static void RegisterExtension(Channel channel, StandardOpenIdExtensionFactory.CreateDelegate extensionFactory)
        {
            ErrorUtilities.VerifyArgumentNotNull(channel, "channel");

            var factory = (OpenIdExtensionFactoryAggregator)channel.BindingElements.OfType<ExtensionsBindingElement>().Single().ExtensionFactory;
            factory.Factories.OfType<StandardOpenIdExtensionFactory>().Single().RegisterExtension(extensionFactory);
        }
开发者ID:jcp-xx,项目名称:dotnetopenid,代码行数:7,代码来源:ExtensionTestUtilities.cs


示例18: Ping

			public void Ping(Channel<Ping> channel)
			{
				channel.Send(new Ping
					{
						ResponseChannel = PongChannel
					});
			}
开发者ID:Nangal,项目名称:Stact,代码行数:7,代码来源:PingPong_Specs.cs


示例19: DefaultCtor

 public void DefaultCtor()
 {
     var channel = new Channel();
     Assert.Null(channel.CloudBlobStorage);
     Assert.NotNull(channel.CryptoServices);
     Assert.Null(channel.Endpoint);
 }
开发者ID:AArnott,项目名称:IronPigeon,代码行数:7,代码来源:ChannelTests.cs


示例20: Main

        static void Main()
        {
            DateTime time1 = DateTime.Now;

            s_channel = new Channel<int>();

            MicroThread t2 = new MicroThread(run2);
            t2.Start();

            MicroThread t3 = new MicroThread(run2);
            t3.Start();

            MicroThread t1 = new MicroThread(run1);
            t1.Start();

            Console.WriteLine("Starting producer/consumer test, loops {0}", s_loops);

            Scheduler.Run();

            DateTime time2 = DateTime.Now;

            Console.WriteLine("total {0}", res);
            Console.WriteLine("time {0}ms", (time2 - time1).TotalMilliseconds);
            Console.WriteLine("END");
        }
开发者ID:mono,项目名称:mono-microthreads,代码行数:25,代码来源:TimeTest1.cs



注:本文中的Channel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ChannelAdapter类代码示例发布时间:2022-05-24
下一篇:
C# Changed类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap