HttpWebRequest.BeginGetRequestStream不是异步行为

时间:2013-02-24 23:16:00

标签: windows-phone-7 windows-8

在Windows-8程序中,我按如下方式调用HttpWebRequest.BeginGetRequestStream, 之前已设置httpConnection的地方:

private System.Net.HttpWebRequest httpConnection;
public System.IO.Stream OutputStream 
{
    get 
    {
        lock(syncobj) 
        {
            httpConnection.BeginGetRequestStream
                (new AsyncCallback(getRequestResultCallback), null);
            ...
        }
    }
}

此代码在Windows Phone 7上运行时没有问题。由于某些同步问题 我不需要在这里讨论,我期待(需要)执行BeginGetRequestStream的代码,以及执行getRequestResultCallback的代码 不同的线程。我认为,因为getRequestResultCallback是通过运行的 AsyncCallback,就是这种情况。它在Windows 7中,但并非总是如此 在Windows 8中。下面,我添加了一个显示运行位置的堆栈跟踪 BeginGetRequestStream和getRequestResultCallback在同一个线程上运行。

感谢您理解此问题。

提前致谢, 约翰艾默森

ua-desktop.exe!com.webalo.up.ua.wp.net.WpUaHttpRequest.getRequestResultCallback(System.IAsyncResult result) Line 120    C#
System.dll!System.Net.LazyAsyncResult.Complete(System.IntPtr userToken) + 0x65 bytes    
System.dll!System.Net.ContextAwareResult.CaptureOrComplete(ref System.Threading.ExecutionContext cachedContext, bool returnContext) + 0x81 bytes    
System.dll!System.Net.ContextAwareResult.FinishPostingAsyncOp() + 0x24 bytes    
System.dll!System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback callback, object state) + 0x289 bytes   
ua-desktop.exe!com.webalo.up.ua.wp.net.WpUaHttpRequest.OutputStream.get() Line 31 + 0x37 bytes  C#
...
mscorlib.dll!System.Threading.Tasks.Task.InnerInvoke() + 0x49 bytes 
mscorlib.dll!System.Threading.Tasks.Task.Execute() + 0x32 bytes 
mscorlib.dll!System.Threading.Tasks.Task.ExecutionContextCallback(object obj) + 0x15 bytes  
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xa7 bytes  
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x16 bytes  
mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) + 0xca bytes   
mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) + 0xb3 bytes    
mscorlib.dll!System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x7 bytes 
...

0 个答案:

没有答案