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 859895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:44:22+00:00 2026-05-15T08:44:22+00:00

I have a wierd problem with threading in an ASP.NET application. For some reason,

  • 0

I have a wierd problem with threading in an ASP.NET application. For some reason, when I run the code in the request thread, everything works as expected. But when I run it in a separate thread, nothing happens.
This is verified by calling the below handler with the three flags “on”, “off” and “larma” respectively – in the two first cases everything works, but in the latter nothing happens.

What am I doing wrong here?

In the web project I have a generic handler with the following code:

If task = "on" Then
    Alarm.StartaLarm(personId)
    context.Response.Write("Larmet är PÅ")
ElseIf task = "off" Then
    Alarm.StoppaLarm(personId)
    context.Response.Write("Larmet är AV")
ElseIf task = "larma" Then
    Alarm.Larma(personId)
    context.Response.Write("Larmar... (stängs av automagiskt)")
Else
    context.Response.Write("inget hände - task: " & task)
End If

The Alarm class has the following methods:

Public Shared Sub Larma(ByVal personId As Integer)
    Dim thread As New System.Threading.Thread(New ParameterizedThreadStart(AddressOf Larma_Thread))
    thread.Start(personId)
End Sub

Private Shared Sub Larma_Thread(ByVal personId As Integer)
    StartaLarm(personId)
    Thread.Sleep(1000 * 30)
    StoppaLarm(personId)
End Sub

Public Shared Sub StartaLarm(ByVal personId As Integer)
    SandSMS(True, personId)
End Sub

Public Shared Sub StoppaLarm(ByVal personId As Integer)
    SandSMS(False, personId)
End Sub

Public Shared Sub SandSMS(ByVal setOn As Boolean, ByVal personId As Integer)
    ...
End Sub

UPDATE/CLARIFICATION: I still get the expected response to the client – no error messages – when calling the threaded version.

I also included a forgotten method in the code above.

Update 2:
@Henk, Unfortunately I don’t have the ability to debug, because this problem arises only on our sharp server, which doesn’t have Visual Studio installed and doesn’t allow remote debugging.

However, the SendSMS method sends text messages to my phone, and both the text message web service and my phone agrees that the messages are sent when calling “on” or “off”, but not when calling “larma”.

Since I know that the entire chain Handler->StartaLarm->SandSMS(True/False) works for “on” and “off”, I must assume that the failure occurs somewhere in Handler->Larma->Larma_Thread, and thus is a threading issue.

Update 3: @Vadmyst, after converting your code to VB.NET (which is not my favourite of the two either, but this project requires it…) and modifying it to compile, I arrived at the following (although I’m not 100% certain it still means the same thing…):

ThreadPool.QueueUserWorkItem(New WaitCallback(Function(p As Integer) Larma_Thread(p)))

No success – I have the same results as above… =(

  • 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-15T08:44:22+00:00Added an answer on May 15, 2026 at 8:44 am

    You have an exception in SandSMS called from StartaLarm called from Larma_Thread in the context of a secondary thread. The "nothing happens" behaviour in a multi-threaded application is a strong indication of exception in a secondary thread. The first thing that comes to mind, that is different in a non-request thread of a web application, is that a non-request thread does not have access to Request, Context, Session and such.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really weird problem. The below code works fine if I create
I have a wierd problem with Chrome. I have some go to no where
I have run into a problem joining two strings in Python. I have some
I have a very wierd problem. When i run the file from a different
This is a bit of a wierd problem. (.NET 3.5sp1) I have a UserControl
I have a very wierd problem. I have some data which I show in
I have a problem when I try to Run published Application. When I Run
I have this weird problem with setting up cookies with PHP. Everything worked fine
I'm getting some weird behavior in asp.net MVC2 (at least it's not what I'm
im doing some test with the flicker API and i got a wierd problem

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.