Silverlight的HttpWebRequest.Create异步块内挂起 [英] Silverlight HttpWebRequest.Create hangs inside async block

查看:157
本文介绍了Silverlight的HttpWebRequest.Create异步块内挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个原型RPC调用从Silverlight的(4)JBOSS Web服务器。我已经写了code,它是工作在一个控制台应用程序 - 所以我知道JBoss是响应Web请求。它移植到Silverlight 4中,导致问题:

I am trying to prototype a Rpc Call to a JBOSS webserver from Silverlight (4). I have written the code and it is working in a console application - so I know that Jboss is responding to the web request. Porting it to silverlight 4, is causing issues:

let uri =  new Uri(queryUrl)
// this is the line that hangs
let request : HttpWebRequest = downcast WebRequest.Create(uri)
request.Method <- httpMethod;
request.ContentType <- contentType 

这可能是一个沙箱的问题,因为我的Silverlight是被送达了我的文件系统和URI是本地主机的引用 - 虽然我没有得到哪怕是例外。思考?

It may be a sandbox issue, as my silverlight is being served off of my file system and the Uri is a reference to the localhost - though I am not even getting an exception. Thoughts?

THX

更新1

我创建了一个新的项目,我的移植code过去,现在它是工作;东西必须是不稳定的瓦特/关于F#Silverlight的整合仍在。仍然在调试挂网络AP preciate想法在旧模式创造... ...

I created a new project and ported my code over and now it is working; something must be unstable w/ regard to the F# Silverlight integration still. Still would appreciate thoughts on debugging the "hanging" web create in the old model...

更新2

let uri = Uri("http://localhost./portal/main?isSecure=IbongAdarnaNiFranciscoBalagtas")
// this WebRequest.Create works fine
let req : HttpWebRequest = downcast WebRequest.Create(uri)

let Login = async {
    let uri =  new Uri("http://localhost/portal/main?isSecure=IbongAdarnaNiFranciscoBalagtas")
     // code hangs on this WebRequest.Create
     let request : HttpWebRequest = downcast WebRequest.Create(uri)
     return request
}
Login |> Async.RunSynchronously

我必须失去了一些东西;在异步模块工作在控制台应用程序很好 - ?在Silverlight应用程序是不允许的。

I must be missing something; the Async block works fine in the console app - is it not allowed in the Silverlight App?

推荐答案

(感谢发送这fsbugs,迫使我们采取强硬的样子。)

(Thanks for sending this to fsbugs, to force us to take a hard look.)

问题是 Async.RunSynchronously 。当所谓的UI线程,这阻止UI线程上。而事实证明, WebRequest.Create() Silverlight的调度到UI线程。所以这是一个僵局。

The problem is Async.RunSynchronously. When called on the UI thread, this blocks the UI thread. And it turns out that WebRequest.Create() on Silverlight dispatches to the UI thread. So it is a deadlock.

在一般情况下,尽量避免 Async.RunSynchronously Silverlight的(或任何UI线程)。你可以在这个例子中使用 Async.StartImmediate 。另外,我认为你可以从任何后台线程中调用 RunSynchronously 没有问题。 (我没有尝试过足够的终端到终端的Silverlight的场景自己提供更多的建议尚未。你可以看看

In general, try to avoid Async.RunSynchronously on Silverlight (or on any UI thread). You can use Async.StartImmediate in this example. Alternatively, I think you can call RunSynchronously from any background thread without issues. (I have not tried enough end-to-end Silverlight scenarios myself to offer more advice as yet. You might check out

在F#游戏编程(与Silverlight和WPF)

F#和Silverlight

在客户端 F#异步

F# async on the client side

有关短短的例子。)

(回想起来,F#的设计团队认为,我们也许不应该包括 Async.RunSynchronously 在FSharp.Core Silverlight的;该方法可能违反的精神平台(不阻塞调用)。这是可能的,我们会去precate,在未来的Silverlight方法释放。在另一方面,它仍然没有具有有效用途上的Silverlight,如CPU密集型并行运行在一堆(非-IO)在后台线程并行code)

(In retrospect, the F# design team thinks that we maybe should not have included Async.RunSynchronously in FSharp.Core for Silverlight; the method potentially violates the spirit of the platform (no blocking calls). It's possible we'll deprecate that method in future Silverlight releases. On the other hand, it still does have valid uses for CPU-intensive parallelism on Silverlight, e.g. running a bunch on (non-IO) code in parallel on background threads.)

这篇关于Silverlight的HttpWebRequest.Create异步块内挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆