VB.Net程序设计:用队列控制多线程。
来源:互联网 发布:美工类淘宝首页设计 编辑:程序博客网 时间:2024/05/02 02:40
Queuing Threads from the Generic Queue Class [VB.NET/C# Examples by AceInfinity]
From:http://www.sysnative.com/forums/programming/1117-queuing-threads-generic-queue-class-%5Bvbulletin-net-c-examples-aceinfinity%5D.html
Here's an example I put together for someone on MSDN who wanted to be able to easily create a queue of methods to start new threads, and be able to start them one after another in order. Thought i'd share it here as well, as this can be very useful for managing a Thread Queue. Thread syncrhonization in an application is valuable, and can get somewhat complex as well...
用队列控制多线程。也有一定的用途。
Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load End Sub Private qt As Queue(Of Thread) Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click qt = New Queue(Of Thread) qt.Enqueue(New Thread(AddressOf method1)) qt.Enqueue(New Thread(AddressOf method2)) qt.Enqueue(New Thread(AddressOf method3)) qt(0).Start() End Sub Private Sub UpdateQueue() qt.Dequeue() Sync.Variable = qt.Count End Sub Private Sub method1() Console.WriteLine("method1") Thread.Sleep(3000) UpdateQueue() End Sub Private Sub method2() Console.WriteLine("method2") Thread.Sleep(3000) UpdateQueue() End Sub Private Sub method3() Console.WriteLine("method3") Thread.Sleep(3000) UpdateQueue() End Sub Private WithEvents Sync As New SyncQueueCount Private Sub VariableChanged(ByVal QCount As Integer) Handles Sync.VariableChanged If QCount > 0 Then qt(0).Start() Else MessageBox.Show("Queue Finished") End If End SubEnd ClassPublic Class SyncQueueCount Private S_Int As Integer Public Event VariableChanged(ByVal value As Integer) Public Property Variable() As Integer Get Variable = S_Int End Get Set(ByVal value As Integer) S_Int = value RaiseEvent VariableChanged(S_Int) End Set End PropertyEnd Class
- VB.Net程序设计:用队列控制多线程。
- VB.Net程序设计:控制远程计算机:重启或关闭
- VB.Net程序设计:多线程处理,搜索局域网的计算机。
- VB.Net程序设计:原始多线程例子VS2008版
- vb.net 程序设计规范
- VB.NET中多线程程序开发之线程控制
- ListView 控制 VB.net
- vb.net 鼠标控制
- vb.net多线程例子
- VB.net 多线程实例
- vb.net创建多线程
- VB.NET中的多线程
- VB.net多线程入门
- VB.NET多线程
- VB.NET多线程应用
- VB.NET编程多线程
- vb.net的多线程
- VB.NET多线程应用
- array_slice 数组的 读取一部分
- Xml解析:各个库的分析比较
- 发一个特别有帮助的网站,全是QT程序
- python学习之浅谈django模板
- vsprintf()函数
- VB.Net程序设计:用队列控制多线程。
- 基于会话询问内容的检查表
- java线程状态
- GC Log analysis
- 再读《SAP德国造》
- VBA
- static关键字在C++中的使用技巧
- 音视频编解码学习4
- jQuery操作radio、checkbox、select