私はこのハンドラを持っています。私は内部クラスの 'StartTransfer'メソッドで例外が発生していました(私はその場所をマークしました)。理由はわかりませんが、このメソッドをループすることはわかりません。なぜループに入り、例外メッセージで応答しなかったのですか?例外が発生したときにasync hadlerがループを実行するのはなぜですか?
public sealed class ImageUploadHandler : IHttpAsyncHandler
{
public bool IsReusable { get { return false; } }
public ImageUploadHandler()
{
}
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
{
string token = context.Request.Form["token"];
string albumId = context.Request.Form["albumId"];
string imageDescription = context.Request.Form["description"];
HttpPostedFile imageFile = context.Request.Files["image"];
ImageTransferOperation ito = new ImageTransferOperation(cb, context, extraData);
ito.Start(token, albumId, imageDescription, imageFile);
return ito;
}
public void EndProcessRequest(IAsyncResult result)
{
}
public void ProcessRequest(HttpContext context)
{
throw new InvalidOperationException();
}
private class ImageTransferOperation : IAsyncResult
{
private Object state;
private bool isCompleted;
private AsyncCallback cb;
private HttpContext context;
public WaitHandle AsyncWaitHandle
{
get { return null; }
}
public bool CompletedSynchronously
{
get { return false; }
}
public bool IsCompleted
{
get { return isCompleted; }
}
public Object AsyncState
{
get { return state; }
}
public ImageTransferOperation(AsyncCallback cb, HttpContext context, Object state)
{
this.cb = cb;
this.context = context;
this.state = state;
this.isCompleted = false;
}
public void Start(string token, string albumId, string description, HttpPostedFile file)
{
Dictionary<string, Object> dictionary = new Dictionary<string,object>(3);
dictionary.Add("token", token);
dictionary.Add("albumId", albumId);
dictionary.Add("description", description);
dictionary.Add("file", file);
ThreadPool.QueueUserWorkItem(new WaitCallback(StartTransfer), dictionary);
}
private void StartTransfer(Object state)
{
Dictionary<string, Object> dictionary = (Dictionary<string, Object>)state;
string token = (string)dictionary["token"];
string albumId = (string)dictionary["albumId"];
string description = (string)dictionary["description"];
HttpPostedFile file = (HttpPostedFile)dictionary["file"];
var media = new Facebook.FacebookMediaObject {
FileName = file.FileName,
ContentType = file.ContentType
};
using (var binaryReader = new BinaryReader(file.InputStream))
{
media.SetValue(binaryReader.ReadBytes(Convert.ToInt32(file.InputStream.Length)));
}
dictionary.Clear();
dictionary.Add("message", description);
dictionary.Add("source", media);
var client = new Facebook.FacebookClient(token); // <-- Here is where the exception occured
//var result = client.Post("/" + albumId + "/photos", dictionary);
context.Response.ContentType = "text/plain";
context.Response.Write(token + " | " + file.FileName);
//context.Response.Write(result.ToString());
isCompleted = true;
cb(this);
}
}
}
ありがとう:
ここであなたの
ImageTransferOperation
クラスにはいくつかのリビジョンです:バック例外を伝播するImageUploadHandler
にそして。私はコードをデバッグしたときにVSが例外を処理しなかったことを示し、コード実行を続行すると例外が再びスローされたことを意味するループを繰り返します。 – aikixd
私はVisual Studioでも以前の動作を見てきました。私はそれが "例外アシスタントを有効にする - >未処理の例外に呼び出しスタックを巻き戻す"デバッガ機能を有効にした結果だと思います。 –