8
8
using System . Reactive . Disposables ;
9
9
using System . Reactive . Linq ;
10
10
using System . Reactive . Subjects ;
11
+ using System . Threading ;
11
12
using System . Windows ;
12
13
using System . Windows . Media ;
13
14
@@ -116,7 +117,7 @@ private async void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
116
117
{
117
118
try
118
119
{
119
- Client = await new InterReactClientConnector ( ) . ConnectAsync ( ) ;
120
+ Client = await InterReactClient . ConnectAsync ( ) ;
120
121
}
121
122
catch ( Exception exception )
122
123
{
@@ -152,19 +153,21 @@ private async void UpdateSymbol(string symbol)
152
153
Contract contract = new ( )
153
154
{
154
155
Symbol = symbol ,
155
- SecurityType = SecurityType . Stock ,
156
+ SecurityType = ContractSecurityType . Stock ,
156
157
Currency = "USD" ,
157
158
Exchange = "SMART"
158
159
} ;
159
160
161
+ CancellationTokenSource cts = new ( ) ;
162
+ cts . CancelAfter ( TimeSpan . FromSeconds ( 2 ) ) ;
163
+
160
164
try
161
165
{
162
- List < ContractDetails > cds = await Client !
166
+ IList < ContractDetails > cds = await Client !
163
167
. Service
164
- . GetContractDetailsAsync ( contract )
165
- . WaitAsync ( TimeSpan . FromSeconds ( 2 ) ) ;
168
+ . GetContractDetailsAsync ( contract , cts . Token ) ;
166
169
167
- ContractDetails cd = cds . First ( ) ;
170
+ ContractDetails cd = cds . First ( ) ;
168
171
169
172
// Display the stock name.
170
173
Description = cd . LongName ;
@@ -186,7 +189,7 @@ private async void UpdateSymbol(string symbol)
186
189
private void SubscribeToTicks ( Contract contract )
187
190
{
188
191
// Create the observable which will emit realtime updates.
189
- IConnectableObservable < object > ticks = Client !
192
+ IConnectableObservable < IHasRequestId > ticks = Client !
190
193
. Service
191
194
. CreateTickObservable ( contract )
192
195
. ObserveOnDispatcher ( )
@@ -197,7 +200,7 @@ private void SubscribeToTicks(Contract contract)
197
200
TicksConnection = ticks . Connect ( ) ;
198
201
}
199
202
200
- private void SubscribeToTicks ( IObservable < object > ticks )
203
+ private void SubscribeToTicks ( IObservable < IHasRequestId > ticks )
201
204
{
202
205
ticks . Subscribe ( onNext : _ => { } , onError : exception => MessageBox . Show ( $ "Fatal: { exception . Message } ") ) ;
203
206
ticks . OfTickClass ( t => t . Alert ) . Subscribe ( alert => MessageBox . Show ( $ "{ alert . Message } ") ) ;
0 commit comments