HttpContext is Nothing in new Thread inside a control

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default HttpContext is Nothing in new Thread inside a control

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

    Private Sub StartParallelProc(ByVal Command As SqlClient.SqlCommand)

    Dim T As New Threading.Thread(AddressOf ParallelProc)

    Command.Parameters("MyID").Value = Guid.NewGuid.ToString

    System.Web.HttpContext.Current.Session("ID") = Command

    T.Start()

    End Sub

    Private Sub ParallelProc()

    Dim Command As SqlClient.SqlCommand = DirectCast(System.Web.HttpContext.Current.Session( "ID") ,SqlClient.SqlCommand )

    Command.ExecuteNonQuery()

    'other code...


    End Sub

    The StartParallelProc procedure is called from the CreateChildControls of the Control.

    Now, inside the ParallelProc, in the new thread, the System.Web.HttpContext.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?)

    Claudio Biagioli Guest

  2. Similar Questions and Discussions

    1. Validator for server control inside user control
      Hello, I am facing a strange situation and have already spent a lot of time on this. I have a user control 'U' that consists of a...
    2. Newbie:Using ASP.NET thread pool thread to dispatch TCP data, etc.
      Hi, I've an ASP.NET web service which distributes events to clients via TCP. Environment is IIS6 on Windows 2003 server with .NET framework 1.1...
    3. Thread: Control Overrides Page
      Hello I would like to be able that my control overrides the complete live circle of the page. The event is trigger by a Query string value. I...
    4. HttpContext.Current.User vs. Thread.CurrentPrincipal
      How are HttpConext.Current.User and Thread.CurrentPrincipal different? It seems that they can be set differently in different places. Why would...
    5. Could not instantiate ActiveX control because the current thread is not in a si
      Getting "Could not instantiate ActiveX control because the current thread is not in a single-threaded apartment. " error while using AxMSComLib...
  3. #2

    Default 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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  4. #3

    Default 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:eW8lENyODHA.2284@TK2MSFTNGP11.phx.gbl...
    > 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 [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    William F. Robertson, Jr. Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139