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);