Skip to content

Commit 2a7e3a9

Browse files
committed
Properly shutdown of PriceUpdateMultiThreaded
Disposing the PriceSubscription objects.
1 parent 6228c04 commit 2a7e3a9

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

TTAPI/C#/PriceUpdateMultiThreaded/frmPriceUpdateMultiThreaded.cs

+14-9
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,23 @@ void instrRequest_Completed(object sender, InstrumentLookupSubscriptionEventArgs
194194
/// <param name="instrument">TT API Instrument</param>
195195
private void CreateDispatcher(object instrument)
196196
{
197-
WorkerDispatcher dispatcher = Dispatcher.AttachWorkerDispatcher();
197+
using (WorkerDispatcher dispatcher = Dispatcher.AttachWorkerDispatcher())
198+
{
199+
// set the dispatcher to the associated model
200+
Instrument instr = instrument as Instrument;
201+
m_bindingModels[instr.Key].Dispatcher = dispatcher;
202+
m_bindingModels[instr.Key].ThreadID = Thread.CurrentThread.ManagedThreadId.ToString();
198203

199-
// set the dispatcher to the associated model
200-
Instrument instr = instrument as Instrument;
201-
m_bindingModels[instr.Key].Dispatcher = dispatcher;
202-
m_bindingModels[instr.Key].ThreadID = Thread.CurrentThread.ManagedThreadId.ToString();
204+
// Create the price subscription.
205+
CreatePriceSubscription(instr);
203206

204-
// Create the price subscription.
205-
CreatePriceSubscription(instr);
207+
// start routing messages for this thread
208+
dispatcher.Run();
206209

207-
// start routing messages for this thread
208-
dispatcher.Run();
210+
// Shutdown the price subscription (will be called when the dispatcher.BeginInvokeShutdown is called)
211+
m_bindingModels[instr.Key].Subscription.FieldsUpdated -= priceSubscription_FieldsUpdated;
212+
m_bindingModels[instr.Key].Subscription.Dispose();
213+
}
209214
}
210215

211216
/// <summary>

0 commit comments

Comments
 (0)