无法使用(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;
答案 0 :(得分:1)
请使用此...
context.Terminate()