Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3999938
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:43:12+00:00 2026-05-20T07:43:12+00:00

A have ASP.NET 2.0 web application that should allow sending emails. I have a

  • 0

A have ASP.NET 2.0 web application that should allow sending emails. I have a windows service that sends emails immediately. My web application composes email message according to some template and put it in MSMQ and the service get it from there.

The problem is that composing message from template can take some time and I don’t want user to wait while message is composed and passed to the service.

I think about some background process that will listen internal queue of notifications requests. If queue is empty the process do nothing, but as soon as message appeared it begins to process message. I want to have only a single process to not to create a lot of threads.

Currently my idea is to write task scheduler, that will contain queue of notifications requests. When new item is added to the queue the scheduler checks whether process of sending notifications is running. If yes, then it just add the request to the queue. Otherwise it creates new thread that will read the queue until it is empty and perform notification requests.

My concern is I need to be sure my thread will not die after ASP.NET finish the response to a client because it is parent thread for my thread. And the question is what is the best way to do it (or is it possible to do it)?

P.S. It is ok that my thread dies if IIS recycles ASP.NET process due to user inactivity.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:43:12+00:00Added an answer on May 20, 2026 at 7:43 am

    I use the class below as a base class. I inherit from this class and put my logic inside it. I then store the instance of this class in the ASP.Net cache so that a reference is kept and I can always find it. For your purposes after inheriting from this class inside of ExecuteProcess create an infinite while loop “while(true)”, then put a delay at the top/bottom of the loop “thread.sleep(500)”, or something like that. Each loop check for messages in the queue.

    Imports System.Threading
    
    Public MustInherit Class LongRunningProcess
        Public ReadOnly Property Running() As Boolean
            Get
                Return _Running
            End Get
        End Property
    
        Public ReadOnly Property Success() As Boolean
            Get
                Return _Success
            End Get
        End Property
    
        Public ReadOnly Property Exception() As Exception
            Get
                Return _Exception
            End Get
        End Property
    
        Public ReadOnly Property StartTime() As DateTime
            Get
                Return _StartTime
            End Get
        End Property
    
        Public ReadOnly Property EndTime() As DateTime
            Get
                Return _EndTime
            End Get
        End Property
    
        Public ReadOnly Property Args() As Object
            Get
                Return _Args
            End Get
        End Property
    
    
        Protected _Running As Boolean = False
        Protected _Success As Boolean = False
        Protected _Exception As Exception = Nothing
        Protected _StartTime As DateTime = DateTime.MinValue
        Protected _EndTime As DateTime = DateTime.MinValue
        Protected _Args() As Object = Nothing
        Protected WithEvents _Thread As Thread
    
        Private _locker As New Object()
    
        Public Sub Execute(ByVal Arguments As Object)
            SyncLock (_locker)
                'if the process is not running, then...'
                If Not _Running Then
                    'Set running to true'
                    _Running = True
                    'Set start time to now'
                    _StartTime = DateTime.Now
                    'set arguments'
                    _Args = Arguments
                    'Prepare to process in a new thread'
                    _Thread = New Thread(New ThreadStart(AddressOf ExecuteProcess))
    
                    'Start the thread'
                    _Thread.Start()
                End If
            End SyncLock
        End Sub
    
        Protected MustOverride Sub ExecuteProcess()
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.net web service that I'm using for a web application which
I have an asp.net mvc application that uses web service. I have various controllers
I have an ASP.NET web application that is using forms authentication. Everything is configured
I have an ASP.NET web application that, for whatever reason, when it is deployed
We have a asp.net 2.0 web application that is running on IIS7. It is
I am developing an ASP.NET web application that incorporates google maps. I have an
i have a couple of xml files in my asp.net web application that i
Let me share the following scenario: I have a ASP.NET intranet Web-based application that
I have an Asp.Net MVC application that works in the vs.net development web server.
I have a silverlight application that I am embedding in an existing ASP.NET web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.