Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   multi-threading (http://www.velocityreviews.com/forums/t82680-multi-threading.html)

chxant 07-14-2004 09:17 AM

multi-threading
 
Hi,

I tried a simple example of multi-threading, but it's not working.
test() is never excecuted.
What's wrong??

This is the code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;

namespace Threading
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

Thread background = new Thread(new ThreadStart(test));
background.Start();
}
private void test(){
Label1.Text="ok";
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

Bruno Jouhier [MVP] 07-14-2004 09:30 AM

Re: multi-threading
 
What are you trying to do? You do not wait for the thread to complete so the
test method may very well execute after the page has been generated (this is
actually very likely). Then, it is normal that you don't see anything.

Bruno.

"chxant" <chxant@yahoo.com> a écrit dans le message de
news:864959e7.0407140117.57d82307@posting.google.c om...
> Hi,
>
> I tried a simple example of multi-threading, but it's not working.
> test() is never excecuted.
> What's wrong??
>
> This is the code:
> using System;
> using System.Collections;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.SessionState;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.HtmlControls;
> using System.Threading;
>
> namespace Threading
> {
> /// <summary>
> /// Summary description for WebForm1.
> /// </summary>
> public class WebForm1 : System.Web.UI.Page
> {
> protected System.Web.UI.WebControls.Label Label1;
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
>
> Thread background = new Thread(new ThreadStart(test));
> background.Start();
> }
> private void test(){
> Label1.Text="ok";
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeComponent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
> #endregion
> }
> }




tommy b 07-14-2004 10:22 AM

Re: multi-threading
 
Thanks for your answer.
I'll try to explain what I'm trying to do.
I've got a web application with a request to a dbase. This request takes
some time. So, I want to inform the client using multi-threading.

I never used this, that's why I created a new (simple) project just to
try it out.
I know it's possible to simulate a long process using
Thread.Sleep(10000). But ... how can I "force" to excecute test() before
the page has been generated???

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Scott Allen 07-14-2004 02:53 PM

Re: multi-threading
 
I have an article on this issue here:
http://odetocode.com/Articles/112.aspx

Note that I would only recommend using background threads for Page
processing in very unique circumstances. In most cases I feel you may
be hurting scalability.

--
Scott
http://www.OdeToCode.com

On Wed, 14 Jul 2004 03:22:35 -0700, tommy b <chxant@yahoo.com> wrote:

>Thanks for your answer.
>I'll try to explain what I'm trying to do.
>I've got a web application with a request to a dbase. This request takes
>some time. So, I want to inform the client using multi-threading.
>
>I never used this, that's why I created a new (simple) project just to
>try it out.
>I know it's possible to simulate a long process using
>Thread.Sleep(10000). But ... how can I "force" to excecute test() before
>the page has been generated???
>
>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it!




All times are GMT. The time now is 06:07 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.