如何为WebRuby中设置WebRequest.getResponseAsync的处理程序?
-
21-12-2019 - |
题
我正在尝试:
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 )
.
但具有以下错误:
can't convert System::Threading::Tasks::Task into System::Action[System::Threading::Tasks::Task] (TypeError)
.
upd
在
上responseTask = request.GetResponseAsync
action = Action[Task].new { process_request( sender, e ) }
responseTask.Wait( TimeSpan.new( -1 ) )
responseTask.ContinueWith( action )
.
我收到这个错误:
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)
. 解决方案
continuewith需要一个
Action<Task>
.
并具有其他过载,但不是任务。
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可能让您跳过通用类型专业化,即非通用任务,这是您问题的完全键入版本:
action = Action[Task[WebResponse]].new { process_request( sender, e ) }
. 不隶属于 StackOverflow