是否有必要在 NetMQ 中作为订阅者顶部“锁定”
我想是的,我在下面做的点似乎是正确的地方吗?
private void Subscribe()
{
using (var client = new SubscriberSocket())
{
client.Options.ReceiveHighWatermark = 1000;
client.Connect(Connection);
client.Subscribe(Key);
while (true)
{
string address = client.ReceiveFrameString();
lock (SubLock)
{
int newSeqNum = int.Parse(client.ReceiveFrameString());
SendDTTxt = client.ReceiveFrameString();
string contents = client.ReceiveFrameString();
if (SeqNum == -1)
SeqNum = newSeqNum - 1;
if (newSeqNum != SeqNum + 1)
{
throw new Exception("[NetMTSub.Subscribe] SeqNum out of sequence");
}
SeqNum = newSeqNum;
UserAction(contents);
}
}
}
}