كيفية تعيين معالج WebRequest.GetResponseAsync في IronRuby?
-
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)
محدث
على
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>
وقد الأخرى الزائدة ، ولكن ليس لهذه المهمة.
على سبيل المثال:
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