public static ThreadContext CreateThreadWithContext(ThreadFunc code, ThreadContext context, bool start) { ThreadStart wrapper = () => { try { CurrentThreadContext = context; context.ThreadResult = code(); } catch (InterruptException) { } catch (Exception ex) { var ex2 = UnwindExceptionIntoNewException(ex); PrintError(ex.ToString()); throw ex2; } finally { CurrentThreadContext = null; } }; var thread = new Thread(wrapper); context.Thread = thread; if (start) { context.Start(); } return(context); }
public static ThreadContext CreateTaskWithContext(ThreadFunc code, ThreadContext context, bool start) { Func <object> wrapper = () => { try { CurrentThreadContext = context; return(code()); } catch (InterruptException) { return(null); } catch (Exception ex) { var ex2 = UnwindExceptionIntoNewException(ex); PrintError(ex.ToString()); throw ex2; } finally { CurrentThreadContext = null; } }; var task = new Task <object>(wrapper); context.Task = task; if (start) { context.Start(); } return(context); }
public static object CreateThreadWithContext(ThreadFunc code, ThreadContext context, bool start) { ThreadStart wrapper = () => { try { CurrentThreadContext = context; context.ThreadResult = code(); } catch (InterruptException) { } catch (Exception ex) { var ex2 = UnwindExceptionIntoNewException(ex); PrintError(ex.ToString()); throw ex2; } finally { CurrentThreadContext = null; } }; var thread = new Thread(wrapper); context.Thread = thread; if (start) { context.Start(); } return context; }
public static object CreateTaskWithContext(ThreadFunc code, ThreadContext context, bool start) { Func<object> wrapper = () => { try { CurrentThreadContext = context; return code(); } catch (InterruptException) { return null; } catch (Exception ex) { var ex2 = UnwindExceptionIntoNewException(ex); PrintError(ex.ToString()); throw ex2; } finally { CurrentThreadContext = null; } }; var task = new Task<object>(wrapper); context.Task = task; if (start) { context.Start(); } return context; }