问题
Using C# and QuickFix/N
I am trying to logout cleanly from an initiator.
initiator.Stop(true);
int tryCount = 5;
while (initiator.IsLoggedOn)
{
tryCount--;
if (tryCount <= 0)
break;
Thread.Sleep(1000);
}
If I previously logged out cleanly - by which I mean I sent and received 35=5 messages. Then the logout works.
However, if I just cut the connection and on login I get 35=4 messages aslking for a reset, then when I try to logout I don't see my own 35=5 in the logs.
Why?
I also got this message at logout on one occasion:
System.ObjectDisposedException was unhandled HResult=-2146232798
Message=Cannot access a disposed object. Object name: 'FileLog'.
Source=QuickFix ObjectName=FileLog StackTrace: at QuickFix.FileLog.DisposedCheck() at QuickFix.FileLog.OnEvent(String s) at QuickFix.Session.Disconnect(String reason) at QuickFix.SocketInitiatorThread.Read() at QuickFix.Transport.SocketInitiator.SocketInitiatorThreadStart(Object socketInitiatorThread) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart(Object obj) InnerException:
EDIT
I have found a solution, which is to log out each session before calling Stop. This is NOT suggested in the documentation.
I thought Stop would implicitly do this.
var sessionIDs = initiator.GetSessionIDs().ToList();
foreach (var sessionID in sessionIDs)
{
Session session = Session.LookupSession(sessionID);
session.Logout("Normal logout");
}
Thread.Sleep(1000);
int tryCount = 5;
while (initiator.IsLoggedOn)
{
tryCount--;
if (tryCount <= 0)
break;
Thread.Sleep(1000);
}
initiator.Stop(true);
回答1:
initiator.Stop(true);
Your initiator has stopped, all sessions terminated, so which session are you logging out of ?
You log out of all sessions cleanly, log off and then stop the initiator. Supposedly one session was still receiving any messages and you stop the initiator without logging them off, your counterparty will try again to send the message, assuming you have crashed. If you log them out, they will realize the session has been terminated and try logging in before sending a message.
来源:https://stackoverflow.com/questions/39976673/logout-not-working-after-seqreset