Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Everything stops when a Thread is running on the server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Amrit Kohli - 31 Jul 2007 15:08 GMT
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 - 31 Jul 2007 15:46 GMT
Post some relevant code

> Hello,
>
[quoted text clipped - 14 lines]
>
> Amrit Kohli
Amrit Kohli - 31 Jul 2007 18:12 GMT
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

> Post some relevant code
>
[quoted text clipped - 16 lines]
> >
> > Amrit Kohli
John Saunders [MVP] - 31 Jul 2007 17:07 GMT
> Hello,
>
[quoted text clipped - 10 lines]
>
> 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.
Signature

John Saunders [MVP]

Amrit Kohli - 31 Jul 2007 18:14 GMT
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

> > Hello,
> >
[quoted text clipped - 17 lines]
> 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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.