HttpContext is Nothing in new Thread inside a control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Claudio Biagioli

    HttpContext is Nothing in new Thread inside a control

    I start a parallel thread inside a control with the following code:

    Private Sub StartParallelPr oc(ByVal Command As SqlClient.SqlCo mmand)

    Dim T As New Threading.Threa d(AddressOf ParallelProc)

    Command.Paramet ers("MyID").Val ue = Guid.NewGuid.To String

    System.Web.Http Context.Current .Session("ID") = Command

    T.Start()

    End Sub

    Private Sub ParallelProc()

    Dim Command As SqlClient.SqlCo mmand = DirectCast(Syst em.Web.HttpCont ext.Current.Ses sion("ID") ,SqlClient.SqlC ommand )

    Command.Execute NonQuery()

    'other code...


    End Sub

    The StartParallelPr oc procedure is called from the CreateChildCont rols of the Control.

    Now, inside the ParallelProc, in the new thread, the System.Web.Http Context.Current property appears to be Nothing.

    Also if I try to access Page.Session property I have an error.

    This does not happen if I have the same code inside a page instead of inside a control.

    Any Idea, solution?

    Do you know alternative ways to communicate between the threads (to pass the ID property and other info?)

  • Natty Gur

    #2
    Re: HttpContext is Nothing in new Thread inside a control

    As far as i know the only way to do it is to pass the Context as
    parameter to the thread. let me know if you need a sample.

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!

    Comment

    • William F. Robertson, Jr.

      #3
      Re: HttpContext is Nothing in new Thread inside a control

      I actually would like a sample of passing a parameter to a thread. I know
      it it possible, but the only thing I could find was NOT passing it to the
      thread.

      Thanks,

      bill

      "Natty Gur" <natty@dao2com. com> wrote in message
      news:eW8lENyODH A.2284@TK2MSFTN GP11.phx.gbl...[color=blue]
      > As far as i know the only way to do it is to pass the Context as
      > parameter to the thread. let me know if you need a sample.
      >
      > Natty Gur, CTO
      > Dao2Com Ltd.
      > 28th Baruch Hirsch st. Bnei-Brak
      > Israel , 51114
      >
      > Phone Numbers:
      > Office: +972-(0)3-5786668
      > Fax: +972-(0)3-5703475
      > Mobile: +972-(0)58-888377
      >
      > Know the overall picture
      >
      >
      > *** Sent via Developersdex http://www.developersdex.com ***
      > Don't just participate in USENET...get rewarded for it![/color]


      Comment

      Working...