zoukankan      html  css  js  c++  java
  • 多线程Demo VB.net

     1 Partial Class Test_MapTest
     2     Inherits System.Web.UI.Page
     3 
     4 
     5     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     6 
     7         Dim StartTime As DateTime = Now
     8 
     9         Dim FABCStatus As New ABCStatus
    10 
    11         For I = 1 To 100
    12             Dim FABC As New ABC(I, FABCStatus)
    13             Dim FThread As New Threading.Thread(AddressOf FABC.Test)
    14             FThread.IsBackground = True
    15             FThread.Start()
    16         Next
    17 
    18         Do While Now.Subtract(StartTime).TotalSeconds < 10
    19             Threading.Thread.Sleep(100)
    20         Loop
    21 
    22         Response.Write(FABCStatus.HTML)
    23     End Sub
    24 
    25 End Class
    26 
    27 Public Class ABCStatus
    28     Public Number As Integer = 0
    29     Public HTML As String = ""
    30 End Class
    31 
    32 Public Class ABC
    33 
    34     Public ThreadID As Integer
    35     Public FABCStatus As ABCStatus
    36 
    37     Public Sub New(ByVal ThreadID As Integer, ByRef FABCStatus As ABCStatus)
    38         Me.ThreadID = ThreadID
    39         Me.FABCStatus = FABCStatus
    40     End Sub
    41 
    42     Public Sub Test()
    43         For I = 1 To 100
    44             Threading.Interlocked.Increment(FABCStatus.Number)
    45             'Number = Number + 1
    46             FABCStatus.HTML = FABCStatus.HTML & "<br>" & ThreadID & ": " & FABCStatus.Number
    47             Threading.Thread.Sleep(100)
    48         Next
    49     End Sub
    50 
    51 End Class
  • 相关阅读:
    Dynamically allocated memory 动态分配内存【malloc】Memory leaks 内存泄漏
    const pointers
    heap是堆,stack是栈
    Java中使用Cookie
    Postman注册、登录、导出、导入
    HttpServletRequest get post 入参
    判断设置的时间是否大于当前时间
    JS回车登录
    一个普通的Ajax
    Java工具类
  • 原文地址:https://www.cnblogs.com/pyblogs/p/3501959.html
Copyright © 2011-2022 走看看