如何在c#中使用zeromq后终止上下文

时间:2013-06-13 06:15:46

标签: c# zeromq

无法使用(var context = new Context(1)){},如何终止它

python有context.term(),但c#没有它!

using (var context = new Context(1))
            {
                //using (Socket server = context.Socket(SocketType.REQ))
                using (Socket server = context.Socket(SocketType.PUB))
                {
                    var serializer = new VpfsLiveFeed.MessageTypes.JsonSerializer();
                    var jsonMessage = new VpfsLiveFeed.MessageTypes.LivefeedEnvelope
                    {
                        Message = new VpfsLiveFeed.MessageTypes.LivefeedMessage
                        {
                            MessageType = "TERMINATION_REQUEST",
                            MessageId = "Testing Message",
                            ReplyEmailAddress = "VPLAB@localhost.com"
                        }
                    };
                    server.Connect(string.Format("tcp://{0}", ConfigurationManager.AppSettings["termination_host"]));
                    server.Send(serializer.MessageToBytes<VpfsLiveFeed.MessageTypes.LivefeedEnvelope>(jsonMessage), Encoding.UTF8);
                    server.Dispose();
                }
                context.Dispose(); // stop here is not go out of this {}
            }
StopAllThread = true;
            System.Console.WriteLine("Stopped");
            if (myHost != null)
                myHost.Close();

它不会去StopAllThread = true;

1 个答案:

答案 0 :(得分:1)

请使用此...

context.Terminate()