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 Unwounding Problems

Thread Unwounding Problems

Scheduled Pinned Locked Moved ASP.NET
csharphelpasp-netdata-structures
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
    DELETEUSER
    wrote on last edited by
    #1

    Scenario - I have a web application in ASP.NET and C# which has a backend as MSMQ. I have a private Microsoft Queue (MSMQ) which has to be constantly read for any contents that are submitted to it by users via webpage. As soon as there is something in the queue, it has to be read and processed. For this I have a thread called QRead in Global.asax. It refers to a static method ReadQ that is in an infinte while loop. the problem is that the application behaves randomly since the thread QRead in continously monitoring the queue and is always active. The CPU usage goes to 100% after the first time you launch tha application. QRead thread cannot be put to sleep since we need it to monitor the queue. I also get a popup sometimes that say "Application failed to start poperly since the thread cannot be unwound out of it. CC92. No source code available." Can some one please help !!! Code is as below ...... Global.asax ------------------------ protected void Application_Start(Object sender, EventArgs e) { Thread QRead = new Thread(new ThreadStart(SthQueueHandler.ReadQ)); QRead.IsBackground = false; QRead.Start(); } ------------------------ ReadQ ------------------------ public static void ReadQ() { while(true) { // CODE TO PROCESS QUEUE CONTENTS } } ------------------------- A student knows little about a lot. A professor knows a lot about little. I know everything about nothing.

    J S 2 Replies Last reply
    0
    • D DELETEUSER

      Scenario - I have a web application in ASP.NET and C# which has a backend as MSMQ. I have a private Microsoft Queue (MSMQ) which has to be constantly read for any contents that are submitted to it by users via webpage. As soon as there is something in the queue, it has to be read and processed. For this I have a thread called QRead in Global.asax. It refers to a static method ReadQ that is in an infinte while loop. the problem is that the application behaves randomly since the thread QRead in continously monitoring the queue and is always active. The CPU usage goes to 100% after the first time you launch tha application. QRead thread cannot be put to sleep since we need it to monitor the queue. I also get a popup sometimes that say "Application failed to start poperly since the thread cannot be unwound out of it. CC92. No source code available." Can some one please help !!! Code is as below ...... Global.asax ------------------------ protected void Application_Start(Object sender, EventArgs e) { Thread QRead = new Thread(new ThreadStart(SthQueueHandler.ReadQ)); QRead.IsBackground = false; QRead.Start(); } ------------------------ ReadQ ------------------------ public static void ReadQ() { while(true) { // CODE TO PROCESS QUEUE CONTENTS } } ------------------------- A student knows little about a lot. A professor knows a lot about little. I know everything about nothing.

      J Offline
      J Offline
      Javier Lozano
      wrote on last edited by
      #2

      First of all, having a thread running in an infite loop in a web application is just poor design. Why do you need to have this thread running? You do know that this thread is taken from the thread pool for the application, which is the same place where request threads come from? What are you trying to read from the queue? Can't you just do it on the Begin_Request event handler for the application? Seems a little better than just an infinite loop. ~Javier Lozano (blog)

      1 Reply Last reply
      0
      • D DELETEUSER

        Scenario - I have a web application in ASP.NET and C# which has a backend as MSMQ. I have a private Microsoft Queue (MSMQ) which has to be constantly read for any contents that are submitted to it by users via webpage. As soon as there is something in the queue, it has to be read and processed. For this I have a thread called QRead in Global.asax. It refers to a static method ReadQ that is in an infinte while loop. the problem is that the application behaves randomly since the thread QRead in continously monitoring the queue and is always active. The CPU usage goes to 100% after the first time you launch tha application. QRead thread cannot be put to sleep since we need it to monitor the queue. I also get a popup sometimes that say "Application failed to start poperly since the thread cannot be unwound out of it. CC92. No source code available." Can some one please help !!! Code is as below ...... Global.asax ------------------------ protected void Application_Start(Object sender, EventArgs e) { Thread QRead = new Thread(new ThreadStart(SthQueueHandler.ReadQ)); QRead.IsBackground = false; QRead.Start(); } ------------------------ ReadQ ------------------------ public static void ReadQ() { while(true) { // CODE TO PROCESS QUEUE CONTENTS } } ------------------------- A student knows little about a lot. A professor knows a lot about little. I know everything about nothing.

        S Offline
        S Offline
        Scott Serl
        wrote on last edited by
        #3

        This is not the way to read from a MessageQueue. Read up on MessgaeQueue.BeginReceive and handling the the event with an eventhandler of type MessageQueue.ReceiveCompleted. Basically, you put all your reading logic in the event handler. Then you make a call to .BeginReceive in your main startup code. When the queue receives a message, your handler will be called, then you end the handler with another call to .BeginReceive. Here is some code:

        static void MyStart()
        {
        Type[] AllowedTypes = {Type.GetType("MyNamespace.Type")};

        //Create queue object
        q = new MessageQueue("queuePath");
        //Initialize que to handle your message objects
        q.Formatter = new XmlMessageFormatter(AllowedTypes);
        //Set up event handler
        q.ReceiveCompleted += new ReceiveCompletedEventHandler(q\_ReceiveCompleted);
        //Start receiving messages
        q.BeginReceive();
        

        }

        private static void q_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
        {
        //Put code here to read from the queue
        //...
        //...
        //Now wait for another message
        q.BeginReceive();
        }

        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