Everything stops when a Thread is running on the server

Discussion in 'ASP .Net' started by =?Utf-8?B?QW1yaXQgS29obGk=?=, Jul 31, 2007.

  1. Hello,

    I have a button that starts up a Thread and runs it in the background.

    While the Thread is running, all the Ajax controls, including the events
    fired by the PageRequestManager, stop firing until the Thread exits. So, I
    have no way of updating the page while this Thread is running, which was the
    point of putting it on the Thread.

    The Ajax timer stops firing. Nothing works. It's very frustrating.

    Can someone please help me?

    Thanks,

    Amrit Kohli
     
    =?Utf-8?B?QW1yaXQgS29obGk=?=, Jul 31, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?QW1yaXQgS29obGk=?=

    Aidy Guest

    Post some relevant code

    "Amrit Kohli" <Amrit > wrote in message
    news:...
    > Hello,
    >
    > I have a button that starts up a Thread and runs it in the background.
    >
    > While the Thread is running, all the Ajax controls, including the events
    > fired by the PageRequestManager, stop firing until the Thread exits. So,
    > I
    > have no way of updating the page while this Thread is running, which was
    > the
    > point of putting it on the Thread.
    >
    > The Ajax timer stops firing. Nothing works. It's very frustrating.
    >
    > Can someone please help me?
    >
    > Thanks,
    >
    > Amrit Kohli
     
    Aidy, Jul 31, 2007
    #2
    1. Advertising

  3. "Amrit Kohli" <Amrit > wrote in message
    news:...
    > Hello,
    >
    > I have a button that starts up a Thread and runs it in the background.
    >
    > While the Thread is running, all the Ajax controls, including the events
    > fired by the PageRequestManager, stop firing until the Thread exits. So,
    > I
    > have no way of updating the page while this Thread is running, which was
    > the
    > point of putting it on the Thread.
    >
    > The Ajax timer stops firing. Nothing works. It's very frustrating.
    >
    > Can someone please help me?


    Are you using Session state? I've recently read that requests for the same
    session are serialized.

    BTW, I hope your background thread doesn't reference anything in the Page or
    Request, or any other part of the HttpContext. Once the page unloads, all of
    that data is invalid, even if your thread is still accessing it.
    --
    John Saunders [MVP]
     
    John Saunders [MVP], Jul 31, 2007
    #3
  4. Aidy,

    Thanks for the response.

    Here's the ASPX code:

    <ajax:ScriptManager id="ScriptManager1" runat="server"
    EnablePartialRendering="true" EnablePageMethods="true"/>
    <ajax:Timer ID="ajaxTimer" runat="server" Interval="1"
    OnTick="ajaxTimer_OnTick" />
    <ajax:UpdatePanel ID="upLoadTools" runat="server"
    UpdateMode="Conditional">
    <ContentTemplate>
    <div class="progress">
    <app:progressBar id="ImportProgressBar" height="20em" runat="server" />
    </div>
    <asp:Button ID="_btnLoadTools" runat="server" CssClass="formbutton"
    Text="Load Tools" OnClick="_btnLoadTools_Click" ToolTip="Load Tools" />
    </ContentTemplate>
    <Triggers>
    <ajax:AsyncPostBackTrigger ControlID="ajaxTimer" EventName="Tick" />
    </Triggers>
    </ajax:UpdatePanel>

    And here's the code that starts the thread:

    protected void _btnLoadTools_Click(object sender, EventArgs e) {
    this.ajaxTimer.Enabled = true;
    Thread t = new Thread((ThreadStart)delegate { CreateTools(); });
    t.IsBackground = true;
    t.Start();
    }

    And here's the code in the Tick event of the Timer:

    protected void ajaxTimer_OnTick(object sender, EventArgs e) {
    this.ImportProgressBar.Percentage = Percentage;
    this.upLoadTools.Update();
    }

    The OnTick event dies after the Thread is started. However, I did figure
    this out.

    I put a conditional Sleep on the Thread that gives up the processor to the
    ASPX worker process. The problem is that the Thread was basically hogging
    the ASPX worker process and wouldn't give up any time to the client. With
    some strategically placed Thread.Sleeps, I was able to get the progress bar
    to update correctly.

    What I didn't realize is that this isn't the same kind of multi-threading
    enviornment that I'm familiar with. If you start a Thread in the ASPX worker
    process' space, it basically takes over the whole process space. If you
    don't put it to sleep, it'll rarely give up the time to the client.

    Thanks for the help and I hope this helps others figure out this problem.

    Amrit
    "Aidy" wrote:

    > Post some relevant code
    >
    > "Amrit Kohli" <Amrit > wrote in message
    > news:...
    > > Hello,
    > >
    > > I have a button that starts up a Thread and runs it in the background.
    > >
    > > While the Thread is running, all the Ajax controls, including the events
    > > fired by the PageRequestManager, stop firing until the Thread exits. So,
    > > I
    > > have no way of updating the page while this Thread is running, which was
    > > the
    > > point of putting it on the Thread.
    > >
    > > The Ajax timer stops firing. Nothing works. It's very frustrating.
    > >
    > > Can someone please help me?
    > >
    > > Thanks,
    > >
    > > Amrit Kohli

    >
    >
    >
     
    =?Utf-8?B?QW1yaXQgS29obGk=?=, Jul 31, 2007
    #4
  5. John,

    I was using the Session to pass values back to the Progress Bar. However, I
    stopped doing that. I now use a static variable to do the same thing. There
    are other alternatives like a hidden field, but I'm okay with the static
    field.

    My last post explains how I fixed this problem.

    Thanks for the response.

    Amrit

    "John Saunders [MVP]" wrote:

    > "Amrit Kohli" <Amrit > wrote in message
    > news:...
    > > Hello,
    > >
    > > I have a button that starts up a Thread and runs it in the background.
    > >
    > > While the Thread is running, all the Ajax controls, including the events
    > > fired by the PageRequestManager, stop firing until the Thread exits. So,
    > > I
    > > have no way of updating the page while this Thread is running, which was
    > > the
    > > point of putting it on the Thread.
    > >
    > > The Ajax timer stops firing. Nothing works. It's very frustrating.
    > >
    > > Can someone please help me?

    >
    > Are you using Session state? I've recently read that requests for the same
    > session are serialized.
    >
    > BTW, I hope your background thread doesn't reference anything in the Page or
    > Request, or any other part of the HttpContext. Once the page unloads, all of
    > that data is invalid, even if your thread is still accessing it.
    > --
    > John Saunders [MVP]
    >
    >
     
    =?Utf-8?B?QW1yaXQgS29obGk=?=, Jul 31, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Todd

    Timer thread stops running

    Todd, Apr 6, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    3,961
  2. Phil
    Replies:
    3
    Views:
    4,235
  3. =?Utf-8?B?bWFyZWFs?=

    Thread just stops running

    =?Utf-8?B?bWFyZWFs?=, Mar 8, 2005, in forum: ASP .Net
    Replies:
    9
    Views:
    562
    Kevin Spencer
    Mar 9, 2005
  4. Matt Rapoport

    Thread suddenly stops in NT Service

    Matt Rapoport, Jul 15, 2003, in forum: Python
    Replies:
    0
    Views:
    327
    Matt Rapoport
    Jul 15, 2003
  5. Fabrizio J. Bonsignore syntotic

    Indeed, thread index downloads, everything else BLANK SCREEN

    Fabrizio J. Bonsignore syntotic, Mar 1, 2012, in forum: C++
    Replies:
    0
    Views:
    229
    Fabrizio J. Bonsignore syntotic
    Mar 1, 2012
Loading...

Share This Page