簡體   English   中英

在C#中使用zeromq后如何終止上下文

[英]How to terminate context after using zeromq in c#

無法使用(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;

只是使用這個...

context.Terminate()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM