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. Threading in ASP.NET

Threading in ASP.NET

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminquestion
6 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.
  • R Offline
    R Offline
    rmccart2
    wrote on last edited by
    #1

    I have a need to send a large number of emails to members of a community. I currently do this by sending each member an email with SMTP. This works but take too long to complete. So I was thinking of starting a new thread on the server to send the actual emails, thereby releasing the client browser to go on to other things. But this doesn't seem to work. When debugging the new thread seems to have to complete before return control back to the client browser. Does anyone have any ideas or suggestion that I could implement that would allow the web server to go off on its own to send the emails once initiated from the client? Thanks .... Ron

    T T 2 Replies Last reply
    0
    • R rmccart2

      I have a need to send a large number of emails to members of a community. I currently do this by sending each member an email with SMTP. This works but take too long to complete. So I was thinking of starting a new thread on the server to send the actual emails, thereby releasing the client browser to go on to other things. But this doesn't seem to work. When debugging the new thread seems to have to complete before return control back to the client browser. Does anyone have any ideas or suggestion that I could implement that would allow the web server to go off on its own to send the emails once initiated from the client? Thanks .... Ron

      T Offline
      T Offline
      tojamismis
      wrote on last edited by
      #2

      Threading is my weak spot, so I'll give you a potential different path. You could use Process.Start instead. Place the logic for sending the emails in a separate exe on your server. Have this exe pull the data for the emails from a data store of some sort, and then run the exe with Process.Start. (The default setting for Start is to kick it off without you waiting for it to return results.) Torin Blair - MCP
      'In the immortal words of Socrates - "I drank what?".'

      R 1 Reply Last reply
      0
      • R rmccart2

        I have a need to send a large number of emails to members of a community. I currently do this by sending each member an email with SMTP. This works but take too long to complete. So I was thinking of starting a new thread on the server to send the actual emails, thereby releasing the client browser to go on to other things. But this doesn't seem to work. When debugging the new thread seems to have to complete before return control back to the client browser. Does anyone have any ideas or suggestion that I could implement that would allow the web server to go off on its own to send the emails once initiated from the client? Thanks .... Ron

        T Offline
        T Offline
        TheSnakeByte
        wrote on last edited by
        #3

        post the code you use to start the thread something like: (new System.Threading.Thread(new System.Threading.ThreadStart(TaskMethod)).Start(); in theory this should work although I'm not sure whether there's any timeout for threads on ASP.NET maybe you could open a popup-page for the sending... so the client would know when he's done but still can use his main-browser-window...

        R 1 Reply Last reply
        0
        • T TheSnakeByte

          post the code you use to start the thread something like: (new System.Threading.Thread(new System.Threading.ThreadStart(TaskMethod)).Start(); in theory this should work although I'm not sure whether there's any timeout for threads on ASP.NET maybe you could open a popup-page for the sending... so the client would know when he's done but still can use his main-browser-window...

          R Offline
          R Offline
          rmccart2
          wrote on last edited by
          #4

          Here is the code I'm using: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ' Supply the state information required by the task. Dim tws As New ThreadWithState("This report displays the number {0}.", 42) ' Create a thread to execute the task, and then ' start the thread. Dim t As New Threading.Thread(AddressOf tws.ThreadProc) t.Start() Console.WriteLine("Main thread does some work, then waits.") t.Join() Console.WriteLine("Independent task has completed; main thread ends.") End Sub Public Class ThreadWithState ' The ThreadWithState class contains the information needed for ' a task, and the method that executes the task. ' ' State information used in the task. Private boilerplate As String Private value As Integer ' The constructor obtains the state information. Public Sub New(ByVal text As String, ByVal number As Integer) boilerplate = text value = number End Sub ' The thread procedure performs the task, such as formatting ' and printing a document. Public Sub ThreadProc() Console.WriteLine(boilerplate, value) 'Mail Test Dim mailTo As String = "rmccart2@tampabay.rr.com" Dim mailFrom As String = "TestApplication" Dim mailSubject As String = "Thread with State" Dim mailMsg As String = "This is the test message" Dim myMail As New MyMail(mailTo, mailFrom, mailSubject, mailMsg) If myMail.sendMail() Then 'Mail succeeded Else 'Mail Failed End If End Sub End Class Not familiar with pop-up pages as you also suggest. Could you provide code for that and how to implement? In any case thanks for all your help. Please keep it coming. Ron

          T 1 Reply Last reply
          0
          • T tojamismis

            Threading is my weak spot, so I'll give you a potential different path. You could use Process.Start instead. Place the logic for sending the emails in a separate exe on your server. Have this exe pull the data for the emails from a data store of some sort, and then run the exe with Process.Start. (The default setting for Start is to kick it off without you waiting for it to return results.) Torin Blair - MCP
            'In the immortal words of Socrates - "I drank what?".'

            R Offline
            R Offline
            rmccart2
            wrote on last edited by
            #5

            Torin, First thanks for replying. I thought of trying to handle this in another manner as you suggest. Actually thought a service would be a good alternative. This would though require storing the data, which in itself is not a large matter. Was hoping that I could circumvent the extra work since I already have the code for sending that gets the recipants from the database. But if this threading idea doesn't pan-out then I'll be going down the path you suggest. I just feel that the web server should be able to spawn a thread to do the email business without making the browser wait for a reply. I would however be grateful for any code you may have developed to accomplish your idea of using another exe to handle the email. Thanks ... Ron

            1 Reply Last reply
            0
            • R rmccart2

              Here is the code I'm using: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ' Supply the state information required by the task. Dim tws As New ThreadWithState("This report displays the number {0}.", 42) ' Create a thread to execute the task, and then ' start the thread. Dim t As New Threading.Thread(AddressOf tws.ThreadProc) t.Start() Console.WriteLine("Main thread does some work, then waits.") t.Join() Console.WriteLine("Independent task has completed; main thread ends.") End Sub Public Class ThreadWithState ' The ThreadWithState class contains the information needed for ' a task, and the method that executes the task. ' ' State information used in the task. Private boilerplate As String Private value As Integer ' The constructor obtains the state information. Public Sub New(ByVal text As String, ByVal number As Integer) boilerplate = text value = number End Sub ' The thread procedure performs the task, such as formatting ' and printing a document. Public Sub ThreadProc() Console.WriteLine(boilerplate, value) 'Mail Test Dim mailTo As String = "rmccart2@tampabay.rr.com" Dim mailFrom As String = "TestApplication" Dim mailSubject As String = "Thread with State" Dim mailMsg As String = "This is the test message" Dim myMail As New MyMail(mailTo, mailFrom, mailSubject, mailMsg) If myMail.sendMail() Then 'Mail succeeded Else 'Mail Failed End If End Sub End Class Not familiar with pop-up pages as you also suggest. Could you provide code for that and how to implement? In any case thanks for all your help. Please keep it coming. Ron

              T Offline
              T Offline
              TheSnakeByte
              wrote on last edited by
              #6

              the popup: just another .aspx webpage that says "sending mails..." and does that. when it's done it does a refresh on itself and shows "done" all you have to do is: open that page in a new browser window (like target="_blank" or use javascript) for more details on how to open popups, refer to google and "javascript tutorials" (maybe selfhtml.org) you could also use a iframe but that 'might' be stupid if the user wants to browse somewhere else... anyways, threads on webpages are not the thing to go for and popups are a matter of html/javascript

              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