C# 在c中使用zeromq后如何终止上下文#
无法使用(var context=new context(1)){}退出,如何终止它 python有context.term(),但c#没有C# 在c中使用zeromq后如何终止上下文#,c#,zeromq,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(S
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();
使用(变量上下文=新上下文(1))
{
//使用(socketserver=context.Socket(SocketType.REQ))
使用(socketserver=context.Socket(SocketType.PUB))
{
var serializer=new VpfsLiveFeed.MessageTypes.JsonSerializer();
var jsonMessage=new VpfsLiveFeed.MessageTypes.LivefeedEnvelope
{
Message=new VpfsLiveFeed.MessageTypes.LivefeedMessage
{
MessageType=“终止请求”,
MessageId=“测试消息”,
回复邮件地址=”VPLAB@localhost.com"
}
};
Connect(string.Format(“tcp://{0}”,ConfigurationManager.AppSettings[“termination_host”]);
Send(serializer.MessageToBytes(jsonMessage),Encoding.UTF8);
Dispose();
}
context.Dispose();//在此处停止不会退出此{}
}
StopAllThread=true;
系统控制台写入线(“停止”);
if(myHost!=null)
myHost.Close();
它不会转到StopAllThread=true 用这个
context.Terminate()
我不明白你的意思。你的意思是你不会使用(var context=newcontext(1))块退出那个
?如果是这种情况,您是否看到抛出的异常?在VS2012中,您使用的是clrzmq,在c中没有此函数可供选择ZmqContext.Terminate()
是一种方法,但您使用的是什么版本?@raffian我可以在还剩下套接字时终止上下文吗?当我终止上下文时,套接字是否正确关闭?@leozilla最好先关闭套接字,然后再终止;请参阅来源:@raffian:好的,但我需要关闭/重置创建它们的线程中的套接字,对吗?这增加了一些额外的复杂性。