线程名称 [英] Thread Name

查看:69
本文介绍了线程名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用vs2003,vb.net


我启动一个帖子,在开始之前为它命名。代码片段:


''为每个帖子提供一个唯一的名称(供以后识别)

Trunk_Thread.Name =" Trunk_0_Thread"


''每行只允许1个线程

Trunk_Thread.ApartmentState = ApartmentState.STA


''启动线程实例

Trunk_Thread.Start()


1)在那个帖子中,我希望

Dim x As String = Thread.CurrentThread.Name


返回名称Trunk_0_Thread,但返回nothting。


2)如果我给它的子线程名称为新的


thread.currentthread.name =" Trunk_0_Thread"


然后在帖子中


Dim x As String = Thread.CurrentThread.Name


返回正确的名称。


为什么它在第一次上面的1)中不起作用?


请指教。


Bob Day

解决方
鲍勃


只是一个想法 - 在你的Form_Load或子为主,集当前

线程的名称。看看它是否有所不同。


无论何时我使用Threads,我都会这样做。

Thread.CurrentThread.Name ="主要


问候,

Fergus


该线程是一个没有GUI本身的类一个Windows应用程序。来电看起来好像是
。这是一个非常大的类,但是我在哪里执行

Dim x As String = Thread.CurrentThread.Name

不会改变结果。它可以是新的,或稍后的方法,

返回x =无。


请指教。

Bob

" Peter Huang" <,V - ****** @ online.microsoft.com>在消息中写道

新闻:sA ************** @ cpmsftngxa06.phx.gbl ...

嗨Bob,

您使用的是哪个项目,控制台或Windows应用程序?
您在哪里提到您提到的#1代码?
这将帮助我解决问题。
我期待着您的回复。

问候,
Peter Huang
微软在线合作伙伴支持
获得安全! www.microsoft.com/security
此帖子提供为as as是"没有保证,也没有授予任何权利。



嗨鲍勃,


在您的原始帖子中,您说的是设置sub new中的线程名称是

成功。在这最后一篇文章中,你说sub sub中的x = T.CT.name给了

没有。因为你不能在sub new之前设置名字,你是说你设置了

然后它会怎么样?


把这个混乱放在一边,假设它没有立即消失

分配后,你有没有试过调试过度杀戮来确定什么操作或功能可以擦除名称。

必须有一对

点,这是一分钟之前,现在它已经消失了。


您可能希望发布一个显示此问题的简化项目。这是很难猜到这样的人。


问候,

Fergus

Using vs2003, vb.net

I start a thread, giving it a name before start. Code snippet:

''give each thread a unique name (for later identification)
Trunk_Thread.Name = "Trunk_0_Thread"

'' allow only 1 thread per line
Trunk_Thread.ApartmentState = ApartmentState.STA

'' start thread instance
Trunk_Thread.Start()

1) In that thread, I would expect
Dim x As String = Thread.CurrentThread.Name

To return the the name Trunk_0_Thread, but instead returns nothting.

2) If I give the thread a name in its sub new

thread.currentthread.name= "Trunk_0_Thread"

then later in the thread

Dim x As String = Thread.CurrentThread.Name

returns the proper name.

Why does it not work the in 1) above the first time?

Please advise.

Bob Day

解决方案

Hi Bob,

Just an idea - In your Form_Load or Sub Main, set the name of the current
thread. and see whether it makes any difference.

I do this as a matter of course whenever I work with Threads.
Thread.CurrentThread.Name = "Main"

Regards,
Fergus


The thread is a class with no GUI itself in a windows application. It looks
for incoming telephone calls. This is a very large class, but where I
execute
Dim x As String = Thread.CurrentThread.Name
does not change the results. It can be in sub new, or in a method later on,
both return x = nothing.

Please advise.

Bob
"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:sA**************@cpmsftngxa06.phx.gbl...

Hi Bob,

Which project do you use, Console or Windows application?
Where do you run your code in the #1 you mention?
This will help me to troubleshoot the problem.
I look forward to hearing from you.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.



Hi Bob,

In your original post you said that setting the thread name in sub new was
successful. In this last post you said that x = T.CT.name in sub new gives
nothing.As you can''t set the name before sub new, are you saying that you set
it and then it goes?

Putting that confusion aside, and assuming that it''s not gone immediately
after the assignment, have you tried debug overkill to determine as closely as
possible what operation or function is wiping the name out. There must be a
pair of points at which ''it was here a minute ago'' and ''now it''s gone''.

You may like to post a cut-down project which exhibits this problem. It''s
hard to guess at one like this.

Regards,
Fergus


这篇关于线程名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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