Tôi đang cố gắng đóng phản hồi bằng cách sử dụng Context.Response.End
nhưng nhận lỗi "Thread was being aborted"
.Context.Response.End() và Chủ đề đã bị hủy bỏ
Làm cách nào để đóng đúng phản hồi mà không kích hoạt ngoại lệ?
try {
Context.Response.Clear();
Context.Response.ContentType = "text/html";
//Context.Response.ContentType = "application/json";
JsonObjectCollection collection = new JsonObjectCollection();
collection.Add(new JsonNumericValue("resultcode", 1));
collection.Add(new JsonStringValue("sourceurl", exchangeData.cUrl));
collection.Add(new JsonStringValue("filename", fileName));
collection.Add(new JsonStringValue("filesize", fileSize));
collection.Add(new JsonStringValue("fileurl", Common.GetPDFURL + outputFileName));
JsonUtility.GenerateIndentedJsonText = true;
Context.Response.Write(collection);
try {
Context.Response.End();
} catch (ThreadAbortException exc) {
// This should be first catch block i.e. before generic Exception
// This Catch block is to absorb exception thrown by Response.End
}
} catch (Exception err) {
}
giải quyết bằng bản thân mình, các mã sẽ giống như
try {
Context.Response.End();
} catch (ThreadAbortException err) {
}
catch (Exception err) {
}
Bạn có respose.end bên trong một khối try catch? – Andrew
Tôi đã thêm mã của mình. Có, tôi đã thêm Context.Response.End(); bên trong khối try/catch và khi bạn thấy có khối try/catch chính cũng là lỗi bắt "Thread is aborted". – Tomas
giải quyết bằng bản thân mình, các mã sẽ giống như thử {} catch (err ThreadAbortException) {} catch (Exception err) { } – Tomas