English 中文(简体)
需要多线程vb.net和asp.net的帮助
原标题:need help with multithreading vb.net and asp.net

我的多线程程序不工作,下拉列表要么为空,要么只加载一个。

    Imports System.Threading
Partial Class _Default
    Inherits System.Web.UI.Page

    Public Delegate Sub WaitCallback(ByVal state As Object)


    Private Sub LongTimeTask(ByVal s As Object)

        Dim i As Integer
        Dim str As String
        str = s.ToString

        For i = 0 To 1000
            str = str + "--" + str
        Next

    End Sub

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

        If ThreadPool.QueueUserWorkItem( _
          New WaitCallback(AddressOf LongTimeTask), TextBox1.Text) _
         Then
            Label2.Text = "Queued successfully"
        Else
            Label2.Text = "Failed"
        End If
    End Sub
最佳回答

我不会担心穿那些东西。Page生命周期不会等待线程返回。

http://www.beansoftware.com/ASP.NET-Tutorials/Multithreading-Thread-Pool.aspx

问题回答

首先,线程不能访问彼此“属于”的对象。由于您的网页生命周期是在线程A中处理的,因此th1和th2无法访问那里正在处理的对象。这包括cmb1和cmb2。

其次,在Asp.Net生命周期中,子线程只有在父线程处于活动状态时才处于活动状态。在您的代码中,您以一种“开火并忘记”的方式调用th1.Start()th2.Start()[/code>。正如代码所示,在线程完成其进程并返回到页面生命周期的呈现事件之前,页面生命周期就已经结束了。一旦页面线程结束并将响应推送到客户端,则子线程将成为孤立线程并终止为未完成线程。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!