当前位置: 首页>>代码示例>>C#>>正文


C# Connection.CloseAsync方法代码示例

本文整理汇总了C#中Connection.CloseAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.CloseAsync方法的具体用法?C# Connection.CloseAsync怎么用?C# Connection.CloseAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Connection的用法示例。


在下文中一共展示了Connection.CloseAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CloseConnectionWithDetachTest

        public void CloseConnectionWithDetachTest()
        {
            this.testListener.RegisterTarget(TestPoint.Close, (stream, channel, fields) =>
            {
                // send a detach
                TestListener.FRM(stream, 0x16UL, 0, channel, 0u, true);
                return TestOutcome.Continue;
            });

            string testName = "CloseConnectionWithDetachTest";

            Trace.WriteLine(TraceLevel.Information, "sync test");
            {
                Connection connection = new Connection(this.address);
                Session session = new Session(connection);
                SenderLink sender = new SenderLink(session, "sender-" + testName, "any");
                sender.Send(new Message("test") { Properties = new Properties() { MessageId = testName } });
                connection.Close();
                Assert.IsTrue(connection.Error == null, "connection has error!" + connection.Error);
            }

            Trace.WriteLine(TraceLevel.Information, "async test");
            Task.Factory.StartNew(async () =>
            {
                Connection connection = await Connection.Factory.CreateAsync(this.address);
                Session session = new Session(connection);
                SenderLink sender = new SenderLink(session, "sender-" + testName, "any");
                await sender.SendAsync(new Message("test") { Properties = new Properties() { MessageId = testName } });
                await connection.CloseAsync();
                Assert.IsTrue(connection.Error == null, "connection has error!" + connection.Error);

            }).Unwrap().GetAwaiter().GetResult();
        }
开发者ID:ChugR,项目名称:amqpnetlite,代码行数:33,代码来源:ProtocolTests.cs

示例2: ListenEx

        public async void ListenEx(Connection dataConnection)
        {
            // accept inside try so EndService could clean up.
            try
            {
                await dataConnection.AcceptAsync();
                var protocolHandler = BeginService(dataConnection);
                do
                {
                    // process requests from this connection.
                    protocolHandler.BeginRequest();
                    while (protocolHandler.KeepReading)
                    {
                        await dataConnection.ReadAsync();
                        protocolHandler.CheckRequestData();
                    }

                    // execute collected requests.
                    var stillExecuting = protocolHandler.ParseExecuteRequest();
                    while (stillExecuting > 0)
                    {
                        await dataConnection.FlushAsync(false);
                        stillExecuting = await protocolHandler.WaitForExecuting();
                    }
                    // send last piece of accumulated response to the client.
                    await dataConnection.FlushAsync(true);
                } 
                while (dataConnection.KeepAlive);
                
                // allow chance of graceful close.
                await dataConnection.CloseAsync();
            }
            finally
            {
                //todo: pre-close connection on errors ??
                EndService(dataConnection);
            }
        }
开发者ID:Dataflow-Software,项目名称:Dataflow.NET,代码行数:38,代码来源:Listener.cs

示例3: ReceiveWithConnectionResetTest

        public void ReceiveWithConnectionResetTest()
        {
            this.testListener.RegisterTarget(TestPoint.Flow, (stream, channel, fields) =>
            {
                stream.Dispose();
                return TestOutcome.Continue;
            });

            string testName = "ReceiveWithConnectionResetTest";

            Trace.WriteLine(TraceLevel.Information, "sync test");
            {
                Connection connection = new Connection(this.address);
                Session session = new Session(connection);
                ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, "any");
                DateTime start = DateTime.UtcNow;
                Message message = receiver.Receive();
                Assert.IsTrue(message == null);
                Assert.IsTrue(DateTime.UtcNow.Subtract(start).TotalMilliseconds < 5000, "Receive call is not cancelled.");
                connection.Close();
                Assert.AreEqual(ErrorCode.ConnectionForced, (string)connection.Error.Condition);
            }

            Trace.WriteLine(TraceLevel.Information, "async test");
            Task.Factory.StartNew(async () =>
            {
                Connection connection = await Connection.Factory.CreateAsync(this.address);
                Session session = new Session(connection);
                ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, "any");
                DateTime start = DateTime.UtcNow;
                Message message = await receiver.ReceiveAsync();
                Assert.IsTrue(message == null);
                Assert.IsTrue(DateTime.UtcNow.Subtract(start).TotalMilliseconds < 1000, "Receive call is not cancelled.");
                await connection.CloseAsync();
                Assert.AreEqual(ErrorCode.ConnectionForced, (string)connection.Error.Condition);
            }).Unwrap().GetAwaiter().GetResult();
        }
开发者ID:ChugR,项目名称:amqpnetlite,代码行数:37,代码来源:ProtocolTests.cs

示例4: SendWithInvalidRemoteChannelTest

        public void SendWithInvalidRemoteChannelTest()
        {
            this.testListener.RegisterTarget(TestPoint.Transfer, (stream, channel, fields) =>
            {
                // send an end with invalid channel
                TestListener.FRM(stream, 0x17UL, 0, 33);
                return TestOutcome.Stop;
            });

            string testName = "SendWithProtocolErrorTest";

            Trace.WriteLine(TraceLevel.Information, "sync test");
            {
                Connection connection = new Connection(this.address);
                Session session = new Session(connection);
                SenderLink sender = new SenderLink(session, "sender-" + testName, "any");
                try
                {
                    sender.Send(new Message("test") { Properties = new Properties() { MessageId = testName } });
                    Assert.IsTrue(false, "Send should throw exception");
                }
                catch (AmqpException exception)
                {
                    Assert.AreEqual(ErrorCode.NotFound, (string)exception.Error.Condition);
                }
                connection.Close();
                Assert.AreEqual(ErrorCode.NotFound, (string)connection.Error.Condition);
            }

            Trace.WriteLine(TraceLevel.Information, "async test");
            Task.Factory.StartNew(async () =>
            {
                Connection connection = await Connection.Factory.CreateAsync(this.address);
                Session session = new Session(connection);
                SenderLink sender = new SenderLink(session, "sender-" + testName, "any");
                try
                {
                    await sender.SendAsync(new Message("test") { Properties = new Properties() { MessageId = testName } });
                    Assert.IsTrue(false, "Send should throw exception");
                }
                catch (AmqpException exception)
                {
                    Assert.AreEqual(ErrorCode.NotFound, (string)exception.Error.Condition);
                }
                await connection.CloseAsync();
                Assert.AreEqual(ErrorCode.NotFound, (string)connection.Error.Condition);
            }).Unwrap().GetAwaiter().GetResult();
        }
开发者ID:ChugR,项目名称:amqpnetlite,代码行数:48,代码来源:ProtocolTests.cs


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