Come impostare il gestore per webrequest.gettriponsesysync in IronRuby?
-
21-12-2019 - |
Domanda
Sto provando:
request = WebRequest.Create( uri )
responseTask = request.GetResponseAsync
action = Action.new { process_request( sender, e ) }
task = Task.new( action )
responseTask.Wait( TimeSpan.new( -1 ) )
responseTask.ContinueWith( task )
.
ma avere un errore seguente:
can't convert System::Threading::Tasks::Task into System::Action[System::Threading::Tasks::Task] (TypeError)
.
on
responseTask = request.GetResponseAsync
action = Action[Task].new { process_request( sender, e ) }
responseTask.Wait( TimeSpan.new( -1 ) )
responseTask.ContinueWith( action )
.
Sto ricevendo questo errore:
Found multiple methods for 'ContinueWith': ContinueWith(System::Action[System::Threading::Tasks::Task]), ContinueWith(System::Action[System::Threading::Tasks::Task[System::Net::WebResponse]]) (System::Reflection::AmbiguousMatchException)
. Soluzione
Continuewith prende un
Action<Task>
.
e ha altri sovraccarichi, ma non per un'attività.
EG:
action = Action.new {Console.WriteLine("action")}
task = Task.new( action )
action2 = Action[Task].new{Console.WriteLine("action2")}
task.ContinueWith(action2)
task.Start()
#prints "action" then "action2".
.
.
IronRuby può lasciarti saltare specializzazioni tipo generico Era l'attività non generica, ecco la versione completamente digitata per il tuo problema:
action = Action[Task[WebResponse]].new { process_request( sender, e ) }
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow