Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > multi-threading

Reply
Thread Tools

multi-threading

 
 
chxant
Guest
Posts: n/a
 
      07-14-2004
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
}
}
 
Reply With Quote
 
 
 
 
Bruno Jouhier [MVP]
Guest
Posts: n/a
 
      07-14-2004
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" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed) 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
> }
> }



 
Reply With Quote
 
 
 
 
tommy b
Guest
Posts: n/a
 
      07-14-2004
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!
 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      07-14-2004
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 <(E-Mail Removed)> 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!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments