我可以在asp.net中使用线程吗? [英] can i use threads in asp.net?

查看:78
本文介绍了我可以在asp.net中使用线程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前在几个c#桌面应用程序中使用过线程没有问题,

但似乎无法让这段代码更新我的listBox:


Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理Button1.Click


Dim t作为线程


t =新线程(AddressOf Me.BackgroundProcess)


t.Start()


结束子


私人子背景处理()


Dim i As Integer = 1


做真的


ListBox1.Items.Add(" Iterations:" + i.ToString)


i + = 1


循环


结束子

i''ve used threads in a couple of c# desktop apps with no problems before,
but can''t seem to get this code to update my listBox:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim t As Thread

t = New Thread(AddressOf Me.BackgroundProcess)

t.Start()

End Sub

Private Sub BackgroundProcess()

Dim i As Integer = 1

Do While True

ListBox1.Items.Add("Iterations: " + i.ToString)

i += 1

Loop

End Sub


推荐答案

当第二个线程在BackgroundProcess中开始执行时,

原始线程已经完成执行所需的所有代码,即
渲染页面,页面是完成。


AS P.NET已经是多线程的。有可能你会损害扩展性

添加你自己的主题。


-

Scott
http://www.OdeToCode.com/blogs/scott/

On Tue,2005年11月15日09:57:51 -0500,Dica < ge ***** @ hotmail.com>

写道:
By the time the second thread starts executing in BackgroundProcess,
the original thread has finished executing all the code needed to
render the page, and the page is done.

ASP.NET is already multi-threaded. Chances are you''ll hurt scalability
adding your own threads.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Tue, 15 Nov 2005 09:57:51 -0500, "Dica" <ge*****@hotmail.com>
wrote:
我已经在几个c#桌面应用程序中使用了线程而没有之前的问题,
但似乎无法让这段代码更新我的listBox:

Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As
System。 EventArgs)处理Button1.Click

Dim t As Thread

t =新线程(AddressOf Me.BackgroundProcess)

t.Start()<结束子

私有子BackgroundProcess()

Dim i As Integer = 1

Do While True
ListBox1.Items.Add("迭代:" + i.ToString)

我+ = 1

循环
结束子

i''ve used threads in a couple of c# desktop apps with no problems before,
but can''t seem to get this code to update my listBox:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim t As Thread

t = New Thread(AddressOf Me.BackgroundProcess)

t.Start()

End Sub

Private Sub BackgroundProcess()

Dim i As Integer = 1

Do While True

ListBox1.Items.Add("Iterations: " + i.ToString)

i += 1

Loop

End Sub






Scott,

当你在解释你给Dica他为什么这样做

看不到任何效果,你没有给他如何使它工作。


另外你加入y会损害可扩展性我们自己的主题。并不总是

正确,有些情况下,你需要提交一个搜索(即

花费太长时间)才能在后台工作....


他想要完成的事情可能没有意义,因为他用b / b来解释他的需求,但这是一个合法的问题,我会

喜欢有人回答它!


当后台处理完成时,如何让服务器重新加载页面?b $ b />
-

--Dr。 Abdel

" Scott Allen"写道:
Scott,
while you are correct in the explanation you give Dica about why he does
not see any effect, you didn''t give him how to make it work.

Also "you''ll hurt scalability adding your own threads." is not always
correct, there are situations when you need to submit a search (that is
taking too long) to work in the background....

What he is trying to accomplish may not make sense in the trivial example he
is using to explain his needs, but it is a legitime question, that I would
like someone to answer it!

How to make the server reload the page when the background processing is
done?
--
--Dr. Abdel
"Scott Allen" wrote:
当第二个线程在BackgroundProcess中开始执行时,原始线程已经完成了执行
渲染页面所需的所有代码,并且页面已完成。

ASP.NET已经是多线程的。机会是你会伤害可扩展性
添加你自己的线程。

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

2005年11月15日星期二09 :57:51-505,Dica < ge ***** @ hotmail.com>
写道:
By the time the second thread starts executing in BackgroundProcess,
the original thread has finished executing all the code needed to
render the page, and the page is done.

ASP.NET is already multi-threaded. Chances are you''ll hurt scalability
adding your own threads.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Tue, 15 Nov 2005 09:57:51 -0500, "Dica" <ge*****@hotmail.com>
wrote:
我已经在几个c#桌面应用程序中使用了线程,之前没有问题,<但似乎没有得到这个代码来更新我的listBox:

Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button1 。点击

Dim t As Thread

t =新主题(AddressOf Me.BackgroundProcess)

t.Start()
<结束子

私有子背景过程()

Dim i As Integer = 1

做真的
ListBox1.Items.Add(" Iterations:" + i.ToString)

i + = 1

循环

结束Sub

i''ve used threads in a couple of c# desktop apps with no problems before,
but can''t seem to get this code to update my listBox:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim t As Thread

t = New Thread(AddressOf Me.BackgroundProcess)

t.Start()

End Sub

Private Sub BackgroundProcess()

Dim i As Integer = 1

Do While True

ListBox1.Items.Add("Iterations: " + i.ToString)

i += 1

Loop

End Sub






在ASP.NET 2.0中你有异步页面的概念你可以在请求线程继续使用

其他东西时触发并执行某些任务,但是必须小心使用它c或者正确否则你会花掉两个线程而不是一个线程。


你也可以使用类似AJAX的功能更新你的网页,如果你有/>
a长时间运行的任务你可以检查它是否按一定的时间间隔完成,然后在完成后更新




Do谷歌搜索异步页面,脚本回调,ajax


PL。

" Dr。阿卜杜勒"。 <博士****** @ somewhere.com> skrev i meddelandet新闻:C4 ********************************** @ microsof t.com ...

In ASP.NET 2.0 you have the notion of asynchronous pages where you
can fire off and do some task while the requesting thread continues with
something else, however care must be taken to use it correctly otherwise you''ll
waste two threads instead of one.

You can also use AJAX like functionality to update your pages, if you have
a long running task you can check if it''s done in certain intervals and then update
when it is done.

Do a google search on "asynchronous pages", "script callbacks", "ajax"

PL.
"Dr. Abdel." <Dr******@somewhere.com> skrev i meddelandet news:C4**********************************@microsof t.com...
斯科特,
虽然你在解释中是正确的,但你给Dica讲他为什么没有看到任何效果,你没有给他如何使它发挥作用。另外,你会损害添加自己的线程的可扩展性。并不总是正确的,有些情况下你需要提交一个搜索(即花费太长时间)才能在后台工作....

他是什么试图完成可能在他用来解释他的需求的微不足道的例子中没有意义,但这是一个合法的问题,我会像某人一样回答它!
如何在后台处理完成后让服务器重新加载页面?
-
--Dr。 Abdel

" Scott Allen"写道:
Scott,
while you are correct in the explanation you give Dica about why he does
not see any effect, you didn''t give him how to make it work.

Also "you''ll hurt scalability adding your own threads." is not always
correct, there are situations when you need to submit a search (that is
taking too long) to work in the background....

What he is trying to accomplish may not make sense in the trivial example he
is using to explain his needs, but it is a legitime question, that I would
like someone to answer it!

How to make the server reload the page when the background processing is
done?
--
--Dr. Abdel
"Scott Allen" wrote:
当第二个线程在BackgroundProcess中开始执行时,原始线程已经完成了执行
渲染页面所需的所有代码,并且页面已完成。

ASP.NET已经是多线程的。机会是你会伤害可扩展性
添加你自己的线程。

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

2005年11月15日星期二09 :57:51-505,Dica < ge ***** @ hotmail.com>
写道:
By the time the second thread starts executing in BackgroundProcess,
the original thread has finished executing all the code needed to
render the page, and the page is done.

ASP.NET is already multi-threaded. Chances are you''ll hurt scalability
adding your own threads.

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Tue, 15 Nov 2005 09:57:51 -0500, "Dica" <ge*****@hotmail.com>
wrote:
>我已经在几个c#桌面应用程序中使用了线程而没有任何问题,
>但似乎无法获取此代码来更新我的listBox:
>
> Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As
> System.EventArgs)处理Button1.Click
>
> Dim t As Thread
>
> t =新线程(AddressOf Me.BackgroundProcess)
>
> t.Start()
>
> End Sub
>
> Private Sub BackgroundProcess()
>
> Dim i As Integer = 1
>
> Do While True
>
> ListBox1.Items.Add(" ;迭代:+ i.ToString
>
> i + = 1
>
>循环
>
> ;结束子
>
>
>
>
>
>i''ve used threads in a couple of c# desktop apps with no problems before,
>but can''t seem to get this code to update my listBox:
>
>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles Button1.Click
>
>Dim t As Thread
>
>t = New Thread(AddressOf Me.BackgroundProcess)
>
>t.Start()
>
>End Sub
>
>Private Sub BackgroundProcess()
>
>Dim i As Integer = 1
>
>Do While True
>
>ListBox1.Items.Add("Iterations: " + i.ToString)
>
>i += 1
>
>Loop
>
>End Sub
>
>
>
>
>




这篇关于我可以在asp.net中使用线程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆