473,569 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading in C#.Net Web application

Hi,

I m new to threading and i have successfully runed threading but i
could display value on my web page ,but its working in code behind
when i see it through debugger,plzzzz zzz help me here is the code
below:

i just wana display the simple array value stored in my array variable
in my textbox thats it.

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
//using MultithreadingA pplication.Clas s ;
using System.Threadin g;
using System.Data.Sql Client;

namespace MultithreadingA pplication
{
public class WebForm2 : System.Web.UI.P age
{
string strglobal="";
Object objCust=new Object() ;
int j=0;
protected System.Web.UI.W ebControls.Labe l Label1;
private void Page_Load(objec t sender, System.EventArg s e)
{

ThreadStart simplest = new ThreadStart(Sim plest);
Thread thread1 = new Thread( simplest ) ;

thread1.Start() ;
Label1.Text=str global;
}

public string GetCustomers()//string city)
{
string []str=new string[2] ;
string strsql="select firstname,lastn ame from employees";
SqlConnection conn =new SqlConnection() ;
DataSet CustDS =new DataSet();
conn.Connection String=System.C onfiguration.Co nfigurationSett ings.AppSetting s["ConnectionStri ng"];
SqlCommand commnd=new SqlCommand(strs ql,conn);
SqlDataReader dr ;
conn.Open();
dr=commnd.Execu teReader();
if(dr.Read())
{
for(int i=0;i<1;i++)
{
str[0]=dr["firstname"].ToString() ;

}
}
conn.Close();
TextBox1.Text =j.ToString() ;
j++;

return str[0];

}

public void Simplest()
{
TextBox1.Text=s trglobal;

for(;;)
{
//string i="yy";
strglobal=GetCu stomers();
Thread.Sleep(10 000) ;
}

//Console.WriteLi ne( "Simplest worker - done" ) ;
}

}
}
Please email me if u anybody have the solution i will be very
thankful.

Email:Ya******* *****@netlinkis .com
Nov 17 '05 #1
8 13483
The following statement is going to give problems:
TextBox1.Text=s trglobal;


TextBox1 is created on a different thread than where it is being
assigned. You need to use a delegate and InvokeRequired to do this. See
MSDN for articles by Chris Sells (3 articles) which show how to use
thread in WinForms. Also there is a sample in codeguru. I have listed
all the related links in a post yesterday.

-------
Ajay Kalra
aj*******@yahoo .com

Nov 17 '05 #2
Hi,

This is true in WIN app, not in web app.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ajay Kalra" <aj*******@yaho o.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
The following statement is going to give problems:
TextBox1.Text=s trglobal;


TextBox1 is created on a different thread than where it is being
assigned. You need to use a delegate and InvokeRequired to do this. See
MSDN for articles by Chris Sells (3 articles) which show how to use
thread in WinForms. Also there is a sample in codeguru. I have listed
all the related links in a post yesterday.

-------
Ajay Kalra
aj*******@yahoo .com

Nov 17 '05 #3
My apologies. I have no idea what a web app is.

----------
Ajay Kalra
aj*******@yahoo .com

Nov 17 '05 #4
Hi,

Basically you cannot do it, a web app is a completely different thing that
a win app, once the thread that is handling the request ( the "main"
thread ) is finish all the info was sent to the client and the instance of
the page ( with its controls ) is ready to be GC , in a web app you can
spawn a thread for JUST background processing, to keep doing something after
you sent back the client page.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Yatharth" <ya******@gmail .com> wrote in message
news:ae******** *************** ***@posting.goo gle.com...
Hi,

I m new to threading and i have successfully runed threading but i
could display value on my web page ,but its working in code behind
when i see it through debugger,plzzzz zzz help me here is the code
below:

i just wana display the simple array value stored in my array variable
in my textbox thats it.

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
//using MultithreadingA pplication.Clas s ;
using System.Threadin g;
using System.Data.Sql Client;

namespace MultithreadingA pplication
{
public class WebForm2 : System.Web.UI.P age
{
string strglobal="";
Object objCust=new Object() ;
int j=0;
protected System.Web.UI.W ebControls.Labe l Label1;
private void Page_Load(objec t sender, System.EventArg s e)
{

ThreadStart simplest = new ThreadStart(Sim plest);
Thread thread1 = new Thread( simplest ) ;

thread1.Start() ;
Label1.Text=str global;
}

public string GetCustomers()//string city)
{
string []str=new string[2] ;
string strsql="select firstname,lastn ame from employees";
SqlConnection conn =new SqlConnection() ;
DataSet CustDS =new DataSet();
conn.Connection String=System.C onfiguration.Co nfigurationSett ings.AppSetting s["ConnectionStri ng"];
SqlCommand commnd=new SqlCommand(strs ql,conn);
SqlDataReader dr ;
conn.Open();
dr=commnd.Execu teReader();
if(dr.Read())
{
for(int i=0;i<1;i++)
{
str[0]=dr["firstname"].ToString() ;

}
}
conn.Close();
TextBox1.Text =j.ToString() ;
j++;

return str[0];

}

public void Simplest()
{
TextBox1.Text=s trglobal;

for(;;)
{
//string i="yy";
strglobal=GetCu stomers();
Thread.Sleep(10 000) ;
}

//Console.WriteLi ne( "Simplest worker - done" ) ;
}

}
}
Please email me if u anybody have the solution i will be very
thankful.

Email:Ya******* *****@netlinkis .com

Nov 17 '05 #5
LP
Before delving into threading, read more about underlying technologies of
ASP.NET; specifically HTTP, web server vs. clients browser. It will help you
understand why you can't apply some thing you learned about Windows
programming in a web environment. And why the example you provided is
redicuolos in a web application.
I have seen some "successful " implementation of threading in web
applications, usually when there was a long running task such as long
running sql queries or mass emailing (not spamming). Usually these processes
would take much longer than acceptable in typical web application. A client
browser would make periodic calls to a server checking on the process
progress then updating some html object that resembled a progress bar. These
solutions weren't pretty, programmers have to jump through hoops with clever
mix of client and server side script, often these solutions had unexpected
side effects.
In the end it was decided it's better to optimize SQL queries or have some
kind of batch process that pre-calculates or pre-aggregates data. IMHO use
threading in a web application as the last resort when all other possible
options have been explored.

"Yatharth" <ya******@gmail .com> wrote in message
news:ae******** *************** ***@posting.goo gle.com...
Hi,

I m new to threading and i have successfully runed threading but i
could display value on my web page ,but its working in code behind
when i see it through debugger,plzzzz zzz help me here is the code
below:

i just wana display the simple array value stored in my array variable
in my textbox thats it.

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
//using MultithreadingA pplication.Clas s ;
using System.Threadin g;
using System.Data.Sql Client;

namespace MultithreadingA pplication
{
public class WebForm2 : System.Web.UI.P age
{
string strglobal="";
Object objCust=new Object() ;
int j=0;
protected System.Web.UI.W ebControls.Labe l Label1;
private void Page_Load(objec t sender, System.EventArg s e)
{

ThreadStart simplest = new ThreadStart(Sim plest);
Thread thread1 = new Thread( simplest ) ;

thread1.Start() ;
Label1.Text=str global;
}

public string GetCustomers()//string city)
{
string []str=new string[2] ;
string strsql="select firstname,lastn ame from employees";
SqlConnection conn =new SqlConnection() ;
DataSet CustDS =new DataSet();
conn.Connection String=System.C onfiguration.Co nfigurationSett ings.AppSetting s
["ConnectionStri ng"]; SqlCommand commnd=new SqlCommand(strs ql,conn);
SqlDataReader dr ;
conn.Open();
dr=commnd.Execu teReader();
if(dr.Read())
{
for(int i=0;i<1;i++)
{
str[0]=dr["firstname"].ToString() ;

}
}
conn.Close();
TextBox1.Text =j.ToString() ;
j++;

return str[0];

}

public void Simplest()
{
TextBox1.Text=s trglobal;

for(;;)
{
//string i="yy";
strglobal=GetCu stomers();
Thread.Sleep(10 000) ;
}

//Console.WriteLi ne( "Simplest worker - done" ) ;
}

}
}
Please email me if u anybody have the solution i will be very
thankful.

Email:Ya******* *****@netlinkis .com

Nov 17 '05 #6
Thnx evrybody ,but is there anyway we can do that or if u could create
a demo project and tell me ,since i have to create a thread on a text
box ,suppose data displayed in a textbox from database and if i change
the data from database ,it changes in the text box without page refresh
,or if there is any other way plz suggest me .....

Nov 17 '05 #7
Thnx ,but is there anyway we can do that or if u could create a demo
project and tell me ,since i have to create a thread on a text box
,suppose data displayed in a textbox from database and if i change the
data from database ,it changes in the text box ,or if there is any
other way plz suggest me .....

Nov 17 '05 #8
Thnx ,can we display a message in a textbox coming from database and if
suppose i change the data in database ,the data in the textbox changes
without page refresh.
Plz email me at ya************@ netlinkis.com.

Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
6684
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the language's 30+ year evolution. What to you think python largest compromises are? The three that come to my mind are significant whitespace,...
19
6449
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException. "somethread.interrupt()" will wake somethread up when it's in sleeping/waiting state. Is there any way of doing this with python's thread? I suppose thread...
3
406
by: Avi Kadosh | last post by:
hi all I am new to Csharp I tried the following code using System; using System.Threading;
0
1974
by: Colmeister | last post by:
I recently read Jason Clark's excellent article on Unhandled Exceptions (http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx) and have attempted to incorporate the features he talks about in a new application I'm writing. However, when I try to use ThreadStart to do some work in a separate thread from my GUI, the methods Jason...
2
1412
by: hecklar | last post by:
This is my first time posting here, so i apologize if i'm posting in the wrong subgroup or whatever, but here goes... I’m having a problem with threading and events (permissions?) in a VB.net Windows application (background service). I’m trying to write an application that processes files, launching a new thread for each file that is...
9
1746
by: AdrianJMartin | last post by:
Hi all, I have a need for a STA thread from asp.net. I can create the thread and it runs fine. But when it is finished, the thread still 'hangs' arround. Visible only to the debugger..... I get the "The thread has exited with code 0 (0x12fc)." in the debugger each time the thread seemly end, but its still there in the thread window....
3
2167
by: Aleksandar Cikota | last post by:
Hi all, I have a problem with threading. The following part should be running in a main programm all the time, but so that the main programm also works (like 2 seperate programms, but in one) How to integrate the Code-part in the main programm, so that the mainprogramm works? Code:
6
1890
by: hzgt9b | last post by:
Using VS 2003, .NET: I developed a windows application that performs several actions based on an input file. The application displays a progress bar as each action executes. Based on new requirements, this application needs to be able to shell off other processes and wait while in the mean time displaying a progress bar of the process's. I...
5
10880
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I have a form that has a button. ( this form is a child form of a parent form ( main form ). Anway...in this child form I have a button, and if clicked...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7982
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.