Is it necessary top "lock" as Subscriber in NetMQ
I think it is, would the point I am doing it below seem the right place?
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);
}
}
}
}
As stated in your comment - subscribe is called from one thread:
Since Subscribe is called from only one thread, the lock is unnecessary.
The single thread will just sequentially lock and unlock that block of code for no apparent reason.
It can safely be removed.