Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Thread from code behind aspx

Thread from code behind aspx

Scheduled Pinned Locked Moved ASP.NET
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    devvvy
    wrote on last edited by
    #1

    hello Can I start a thread from aspx code behind (long running stored proc call) Thread SomeThread = new Thread(this.RunLongRunningCommand); SomeThread.Start(SomeArg); I'm worried aspx page worker's thread life cycle.

    dev

    P N 2 Replies Last reply
    0
    • D devvvy

      hello Can I start a thread from aspx code behind (long running stored proc call) Thread SomeThread = new Thread(this.RunLongRunningCommand); SomeThread.Start(SomeArg); I'm worried aspx page worker's thread life cycle.

      dev

      P Offline
      P Offline
      Prosanta Kundu online
      wrote on last edited by
      #2

      Check this 1. [Threading in ASP.NET] 2. [Multi-Threading in ASP.NET]

      1 Reply Last reply
      0
      • D devvvy

        hello Can I start a thread from aspx code behind (long running stored proc call) Thread SomeThread = new Thread(this.RunLongRunningCommand); SomeThread.Start(SomeArg); I'm worried aspx page worker's thread life cycle.

        dev

        N Offline
        N Offline
        NeverHeardOfMe
        wrote on last edited by
        #3

        As an alternative to using System.Threading, which I have to admit I find a difficult class to get to grips with, can I suggest an alternative method for executing a long running process (LRP) within as ASP.NET appliucation... ..this is only of any real use when you can set up your LRP in such a way that you can execute it by passing just an ID number (say to a database record), or at least only a relatively small amount of data to it via a QueryString. Set up your LRP within a generic handler, say "lrp.ashx" Them, in your webapage when you want to execute this, add:

          Try
             Dim request As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(HttpPathOf("lrp.ashx")), System.Net.HttpWebRequest)
             request.Method = "POST"
             request.ContentType = "application/x-www-form-urlencoded"
             Dim postData As String = "id=" & nid.ToString  ' for example - set up whatever data you need to post to the handler here
             request.ContentLength = postData.Length
        
             Dim writer As New System.IO.StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII)
             writer.Write(postData)
             writer.Close()
        
          Catch ex As Exception
             ' whatever
          End Try
        

        Note: by HttpPathOf("lrp.ashx") I mean the full URL (ie starting "http://www.mydomain...." to lrp.ashx - you can't just use a relative URL or Server.MapPath The above code will execute lrp.ashx in a new process, adn you can (for example) immediately redirect to another page while it is still executing, adn yor users will never know.... Perhaps someone here willl tell me why I shouldn't be doiung this, but I've found it works very well :-) And no, I can't translate it into C#! ;P

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups