• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

VB.NET Thread.CurrentThread属性代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.Threading.Thread.CurrentThread属性的典型用法代码示例。如果您正苦于以下问题:VB.NET Thread.CurrentThread属性的具体用法?VB.NET Thread.CurrentThread怎么用?VB.NET Thread.CurrentThread使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Threading.Thread的用法示例。



在下文中一共展示了Thread.CurrentThread属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: Example

' 导入命名空间
Imports System.Collections.Generic
Imports System.Threading
Imports System.Threading.Tasks

Module Example
   Private lockObj As New Object()
   Private rndLock As New Object()
   
   Public Sub Main()
      Dim rnd As New Random()
      Dim tasks As New List(Of Task)
      ShowThreadInformation("Application")

      Dim t As Task(Of Double) = Task.Run( Function()
                                        ShowThreadInformation("Main Task(Task #" + Task.CurrentId.ToString() + ")")
                                        For ctr As Integer = 1 To 20
                                           tasks.Add(Task.Factory.StartNew( Function()
                                                                     ShowThreadInformation("Task #" + Task.CurrentId.ToString())
                                                                     Dim s As Long = 0
                                                                     For n As Integer = 0 To 999999
                                                                        SyncLock rndLock
                                                                           s += rnd.Next(1, 1000001)
                                                                        End SyncLock
                                                                     Next
                                                                     Return s/1000000
                                                                  End Function))
                                        Next

                                        Task.WaitAll(tasks.ToArray())
                                        Dim grandTotal As Double
                                        Console.WriteLine("Means of each task: ")
                                        For Each t In tasks
                                           Console.WriteLine("   {0}", t.Result)
                                           grandTotal += t.Result
                                        Next
                                        Console.WriteLine()
                                        Return grandTotal / 20
                                   End Function )
      Console.WriteLine("Mean of Means: {0}", t.Result)
   End Sub
   
   Private Sub ShowThreadInformation(taskName As String)
      Dim msg As String = Nothing
      Dim thread As Thread = Thread.CurrentThread
      SyncLock lockObj
         msg = String.Format("{0} thread information", taskName) + vbCrLf +
               String.Format("   Background: {0}", thread.IsBackground) + vbCrLf +
               String.Format("   Thread Pool: {0}", thread.IsThreadPoolThread) + vbCrLf +
               String.Format("   Thread ID: {0}", thread.ManagedThreadId) + vbCrLf
      End SyncLock
      Console.WriteLine(msg)
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Threading,代码行数:54,代码来源:Thread.CurrentThread

输出:

Application thread information
Background: False
Thread Pool: False
Thread ID: 1

Main Task(Task #1) thread information
Background: True
Thread Pool: True
Thread ID: 3

Task #2 thread information
Background: True
Thread Pool: True
Thread ID: 4

Task #4 thread information
Background: True
Thread Pool: True
Thread ID: 10

Task #3 thread information
Background: True
Thread Pool: True
Thread ID: 9

Task #5 thread information
Background: True
Thread Pool: True
Thread ID: 3

Task #7 thread information
Background: True
Thread Pool: True
Thread ID: 5

Task #6 thread information
Background: True
Thread Pool: True
Thread ID: 7

Task #8 thread information
Background: True
Thread Pool: True
Thread ID: 6

Task #9 thread information
Background: True
Thread Pool: True
Thread ID: 8

Task #10 thread information
Background: True
Thread Pool: True
Thread ID: 9

Task #11 thread information
Background: True
Thread Pool: True
Thread ID: 10

Task #12 thread information
Background: True
Thread Pool: True
Thread ID: 6

Task #13 thread information
Background: True
Thread Pool: True
Thread ID: 4

Task #14 thread information
Background: True
Thread Pool: True
Thread ID: 3

Task #15 thread information
Background: True
Thread Pool: True
Thread ID: 7

Task #16 thread information
Background: True
Thread Pool: True
Thread ID: 5

Task #17 thread information
Background: True
Thread Pool: True
Thread ID: 8

Task #18 thread information
Background: True
Thread Pool: True
Thread ID: 9

Task #19 thread information
Background: True
Thread Pool: True
Thread ID: 10

Task #20 thread information
Background: True
Thread Pool: True
Thread ID: 4

Task #21 thread information
Background: True
Thread Pool: True
Thread ID: 7

Means of each task:
500038.740584
499810.422703
500217.558077
499868.534688
499295.505866
499893.475772
499601.454469
499828.532502
499606.183978
499700.276056
500415.894952
500005.874751
500042.237016
500092.764753
499998.798267
499623.054718
500018.784823
500286.865993
500052.68285
499764.363303

Mean of Means: 499908.10030605/


示例2: Test

' 导入命名空间
Imports System
Imports System.Data
Imports System.Globalization
Imports System.Threading

public class Test
   public Shared Sub Main
        Thread.CurrentThread.CurrentCulture = New CultureInfo("de-DE")
        Thread.CurrentThread.CurrentUICulture = New CultureInfo("de-DE")

   End Sub
End class
开发者ID:VB程序员,项目名称:System.Threading,代码行数:13,代码来源:Thread.CurrentThread



注:本文中的System.Threading.Thread.CurrentThread属性示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET Type.ContainsGenericParameters属性代码示例发布时间:2022-05-24
下一篇:
VB.NET Task<TResult>.Factory属性代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap