99using System . Windows . Input ;
1010using Netling . Core ;
1111using Netling . Core . Models ;
12+ using Netling . Core . SocketWorker ;
1213
1314namespace Netling . Client
1415{
@@ -55,8 +56,6 @@ private async void StartButton_Click(object sender, RoutedEventArgs e)
5556 var duration = default ( TimeSpan ) ;
5657 int ? count = null ;
5758 var threads = Convert . ToInt32 ( ( ( KeyValuePair < int , string > ) Threads . SelectionBoxItem ) . Key ) ;
58- var threadAffinity = ThreadAffinity . IsChecked . HasValue && ThreadAffinity . IsChecked . Value ;
59- var pipelining = Convert . ToInt32 ( Pipelining . SelectionBoxItem ) ;
6059 var durationText = ( string ) ( ( ComboBoxItem ) Duration . SelectedItem ) . Content ;
6160 StatusProgressbar . IsIndeterminate = false ;
6261
@@ -107,16 +106,12 @@ private async void StartButton_Click(object sender, RoutedEventArgs e)
107106 if ( string . IsNullOrWhiteSpace ( Url . Text ) )
108107 return ;
109108
110- Uri uri ;
111-
112- if ( ! Uri . TryCreate ( Url . Text . Trim ( ) , UriKind . Absolute , out uri ) )
109+ if ( ! Uri . TryCreate ( Url . Text . Trim ( ) , UriKind . Absolute , out var uri ) )
113110 return ;
114111
115112 Threads . IsEnabled = false ;
116113 Duration . IsEnabled = false ;
117114 Url . IsEnabled = false ;
118- Pipelining . IsEnabled = false ;
119- ThreadAffinity . IsEnabled = false ;
120115 StartButton . Content = "Cancel" ;
121116 _running = true ;
122117
@@ -126,10 +121,12 @@ private async void StartButton_Click(object sender, RoutedEventArgs e)
126121 StatusProgressbar . Value = 0 ;
127122 StatusProgressbar . Visibility = Visibility . Visible ;
128123
124+ var worker = new Worker ( new SocketWorkerJob ( uri ) ) ;
125+
129126 if ( count . HasValue )
130- _task = Worker . Run ( uri , count . Value , cancellationToken ) ;
127+ _task = worker . Run ( count . Value , cancellationToken ) ;
131128 else
132- _task = Worker . Run ( uri , threads , threadAffinity , pipelining , duration , cancellationToken ) ;
129+ _task = worker . Run ( threads , duration , cancellationToken ) ;
133130
134131 _task . GetAwaiter ( ) . OnCompleted ( async ( ) =>
135132 {
@@ -172,12 +169,13 @@ private void Urls_OnKeyUp(object sender, KeyEventArgs e)
172169
173170 private async Task JobCompleted ( )
174171 {
172+ if ( _cancellationTokenSource != null && ! _cancellationTokenSource . IsCancellationRequested )
173+ _cancellationTokenSource . Cancel ( ) ;
174+
175175 _running = false ;
176176 Threads . IsEnabled = true ;
177177 Duration . IsEnabled = true ;
178178 Url . IsEnabled = true ;
179- Pipelining . IsEnabled = true ;
180- ThreadAffinity . IsEnabled = true ;
181179 StartButton . IsEnabled = false ;
182180 _cancellationTokenSource = null ;
183181
0 commit comments