silverlight异步请求 httpwebrequest request.BeginGetResponse(new AsyncCallback(ResponseReady), request); allDone.WaitOne();在allDone.WaitOne();执行后就一直等待然后我想实现同步怎么做呀 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class Http { private ManualResetEvent allDone = new ManualResetEvent(false); private string sendData; public delegate void CallBack(string url); public event CallBack CallBackEvent; //post方式 public void PostRequest(string url, string dataStr) { this.sendData = dataStr; Uri endpoint = new Uri(url); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endpoint); request.Method = "POST"; request.ContentType = "text/xml"; request.BeginGetRequestStream(new AsyncCallback(RequestReady), request); allDone.WaitOne(); } void RequestReady(IAsyncResult asyncResult) { HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest; Stream requestStream = request.EndGetRequestStream(asyncResult); StreamWriter sw = new StreamWriter(requestStream); byte[] byteArray = Encoding.Unicode.GetBytes(sendData); sw.Write(sendData); requestStream.Write(byteArray, 0, sendData.Length); sw.Close(); request.BeginGetResponse(new AsyncCallback(ResponseReady), request); } void ResponseReady(IAsyncResult asyncResult) { HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult); try { using (Stream responseStream = response.GetResponseStream()) { StreamReader reader = new StreamReader(responseStream); string retureValue = reader.ReadToEnd(); if (CallBackEvent != null) { CallBackEvent(retureValue); } reader.Close(); } } catch(Exception) { } finally { allDone.Set(); } }这个是个类,我在外面使用的类的PostRequest时候到上面那句就一直等待怎么回事呀,如何实现异步中的同步呀 silverlight 不支持同步请求。只能异步 房屋销售管理系统 #C源码,求解 C# list 提示未对out参数进行赋值 如何设置panel随窗口变大变小自动跟速放. 并发机制 用C#开发这个WEB应用程序,收多少开发费为谊? C#中如何调用 mmioFOURCC()宏 我上传图片到硬盘的文件夹里,当不小心上传了相同名称的图片,此时怎么能该图片正确的存放?就是同名的问题!请提供代码,谢谢 初学C#用什么工具好啊? 哪有图像处理的中文资料啥地?????????????? 取变量的值的问题! 求一winform 程序,判断指定路径下是否存在txt文档 C#用WindowMediaPlayer控件制作视频播放器,右击显示菜单
{
private ManualResetEvent allDone = new ManualResetEvent(false);
private string sendData; public delegate void CallBack(string url);
public event CallBack CallBackEvent; //post方式
public void PostRequest(string url, string dataStr)
{
this.sendData = dataStr;
Uri endpoint = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endpoint);
request.Method = "POST";
request.ContentType = "text/xml";
request.BeginGetRequestStream(new AsyncCallback(RequestReady), request);
allDone.WaitOne(); } void RequestReady(IAsyncResult asyncResult)
{
HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
Stream requestStream = request.EndGetRequestStream(asyncResult);
StreamWriter sw = new StreamWriter(requestStream);
byte[] byteArray = Encoding.Unicode.GetBytes(sendData);
sw.Write(sendData);
requestStream.Write(byteArray, 0, sendData.Length);
sw.Close();
request.BeginGetResponse(new AsyncCallback(ResponseReady), request); }
void ResponseReady(IAsyncResult asyncResult)
{
HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
try
{
using (Stream responseStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream);
string retureValue = reader.ReadToEnd();
if (CallBackEvent != null)
{
CallBackEvent(retureValue);
}
reader.Close();
}
}
catch(Exception)
{ }
finally
{
allDone.Set(); }
}
这个是个类,我在外面使用的类的PostRequest时候到上面那句就一直等待
怎么回事呀,如何实现异步中的同步呀
只能异步