1

在 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 结果) 第 120 行 C#
System.dll!System.Net.LazyAsyncResult.Complete(System.IntPtr userToken) + 0x65 字节    
System.dll!System.Net.ContextAwareResult.CaptureOrComplete(ref System.Threading.ExecutionContext cachedContext, bool returnContext) + 0x81 字节    
System.dll!System.Net.ContextAwareResult.FinishPostingAsyncOp() + 0x24 字节    
System.dll!System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback 回调,对象状态) + 0x289 字节   
ua-desktop.exe!com.webalo.up.ua.wp.net.WpUaHttpRequest.OutputStream.get() 第 31 行 + 0x37 字节 C#
...
mscorlib.dll!System.Threading.Tasks.Task.InnerInvoke() + 0x49 字节
mscorlib.dll!System.Threading.Tasks.Task.Execute() + 0x32 字节
mscorlib.dll!System.Threading.Tasks.Task.ExecutionContextCallback(object obj) + 0x15 字节  
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback 回调, 对象状态, bool preserveSyncCtx) + 0xa7 字节  
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback 回调, 对象状态, bool preserveSyncCtx) + 0x16 字节  
mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) + 0xca 字节   
mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) + 0xb3 字节    
mscorlib.dll!System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x7 字节
...
4

0 回答 0