System.Threading.ThreadPool.QueueUserWorkItem(new SafeWaitCallback().Call(DoTask));
using System;using System.Net;using System.IO;using System.Runtime.Serialization.Formatters.Binary;using System.Runtime.Serialization;public class SafeWaitCallback { public static Uri ApplicationUri; System.Threading.WaitCallback callback; public System.Threading.WaitCallback Call(System.Threading.WaitCallback callback) { this.callback = callback; return CallbackWrapper; } private void CallbackWrapper(object state) { try { callback(state); } catch (Exception e) { byte[] exceptionData; MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Persistence)); formatter.Serialize(stream, e); exceptionData = stream.ToArray(); WebClient client = new WebClient(); Uri handler = new Uri(ApplicationUri, "TransferException.axd"); try { client.UploadData(handler, exceptionData); } catch (WebException) { } } }}
using System;using System.Web;using System.IO;using System.Runtime.Serialization.Formatters.Binary;using System.Runtime.Serialization;public class TransferredExceptionHandler : IHttpHandler { public bool IsReusable { get { return true; }} public void ProcessRequest(HttpContext context) { byte[] exceptionData = new byte[context.Request.ContentLength]; context.Request.InputStream.Read(exceptionData, 0, exceptionData.Length); Exception transferredException; MemoryStream stream = new MemoryStream(exceptionData); BinaryFormatter formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Persistence)); transferredException = (Exception)formatter.Deserialize(stream); throw new Exception("[Background exception transferred - see InnerException]", transferredException); }}
Download AspNetBackgroundExceptions.zip (2.55 KB)
Powered by: newtelligence dasBlog 2.1.8209.14743
Special thanks to LosTechies.com
Site theme based on the essence design by Jelle Druyts
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.