By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

Thread Name

P: n/a
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

Nov 20 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
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
Nov 20 '05 #2

P: n/a
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.

Nov 20 '05 #3

P: n/a
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
Nov 20 '05 #4

P: n/a
Hi Bob,

Here is my code, you may have a try.

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim o As New TestThread
o.ThreadRun()
End Sub

Public Class TestThread
Dim td As Thread
Public Sub New()
' if the three line is moved to the ThreadRun, it works too.
td = New Thread(AddressOf hello)
td.Name = "TestThread"
td.ApartmentState = ApartmentState.STA
End Sub
Public Shared Sub hello()
Debug.WriteLine(Thread.CurrentThread.Name)
End Sub
Public Sub ThreadRun()
td.Start()
End Sub
End Class

Or can you post your code for us to reproduce the problem.

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.
--------------------
From: "Bob Day" <Bo****@TouchTalk.net>
References: <OH**************@TK2MSFTNGP09.phx.gbl> <sA**************@cpmsftngxa06.phx.gbl>Subject: Re: Thread Name
Date: Mon, 3 Nov 2003 17:43:38 -0500
Lines: 30
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <uY**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: dhcp16624016.indy.rr.com 24.166.24.16
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:153330
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

The thread is a class with no GUI itself in a windows application. It looksfor 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.



Nov 20 '05 #5

P: n/a
OK, followed your code exactly, and I think I see where the problem is. The
delegate (i.e. addressOf method) ends with the statement "Application.Run"
since the entire thread is based on a Intel CTADE com object. Following
your code below, the thread name exists before "Application.Run", and
becomes nothing in all methods in the thread after that. I have no idea
why.

As a work around, I replaced your line:
td.Name = "TestThread"
with
thread.currentthread.name = "TestThread"

With that change, immediately before "Application.Run" the name is nothing,
but after "Application.Run" the name is correct ( i.e. "TestThread") in any
method in the tread.

Any ideas? It seems to work, so I will go with it for a while.

Thanks for the code you wrote.

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

Here is my code, you may have a try.

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim o As New TestThread
o.ThreadRun()
End Sub

Public Class TestThread
Dim td As Thread
Public Sub New()
' if the three line is moved to the ThreadRun, it works too.
td = New Thread(AddressOf hello)
td.Name = "TestThread"
td.ApartmentState = ApartmentState.STA
End Sub
Public Shared Sub hello()
Debug.WriteLine(Thread.CurrentThread.Name)
End Sub
Public Sub ThreadRun()
td.Start()
End Sub
End Class

Or can you post your code for us to reproduce the problem.

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.
--------------------
From: "Bob Day" <Bo****@TouchTalk.net>
References: <OH**************@TK2MSFTNGP09.phx.gbl>

<sA**************@cpmsftngxa06.phx.gbl>
Subject: Re: Thread Name
Date: Mon, 3 Nov 2003 17:43:38 -0500
Lines: 30
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <uY**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: dhcp16624016.indy.rr.com 24.166.24.16
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:153330
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

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.


Nov 20 '05 #6

P: n/a
Hi Bob,

I am sorry, but I am not very clear about the problem.
Based on my understanding, you are using VB.NET windows application.
But where do you call the Application.Run method, can you post a simple
sample as long as it can demostrate the problem.
I will be appreciate your efforts.

I look forward to hearing from.
td.Name = "TestThread"
with
thread.currentthread.name = "TestThread" It seems that you set the thread's name in a already running thread.
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.
--------------------From: "Bob Day" <Bo****@TouchTalk.net>
References: <OH**************@TK2MSFTNGP09.phx.gbl> <sA**************@cpmsftngxa06.phx.gbl>
<uY**************@tk2msftngp13.phx.gbl>
<Ik*************@cpmsftngxa06.phx.gbl>Subject: Re: Thread Name disappears after "Application.Run"
Date: Tue, 4 Nov 2003 15:23:07 -0500
Lines: 113
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <eO**************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: dhcp16624016.indy.rr.com 24.166.24.16
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:153626
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

OK, followed your code exactly, and I think I see where the problem is. Thedelegate (i.e. addressOf method) ends with the statement "Application.Run"
since the entire thread is based on a Intel CTADE com object. Following
your code below, the thread name exists before "Application.Run", and
becomes nothing in all methods in the thread after that. I have no idea
why.

As a work around, I replaced your line:
td.Name = "TestThread"
with
thread.currentthread.name = "TestThread"

With that change, immediately before "Application.Run" the name is nothing,
but after "Application.Run" the name is correct ( i.e. "TestThread") in any
method in the tread.

Any ideas? It seems to work, so I will go with it for a while.

Thanks for the code you wrote.

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

Here is my code, you may have a try.

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim o As New TestThread
o.ThreadRun()
End Sub

Public Class TestThread
Dim td As Thread
Public Sub New()
' if the three line is moved to the ThreadRun, it works too.
td = New Thread(AddressOf hello)
td.Name = "TestThread"
td.ApartmentState = ApartmentState.STA
End Sub
Public Shared Sub hello()
Debug.WriteLine(Thread.CurrentThread.Name)
End Sub
Public Sub ThreadRun()
td.Start()
End Sub
End Class

Or can you post your code for us to reproduce the problem.

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. --------------------
>From: "Bob Day" <Bo****@TouchTalk.net>
>References: <OH**************@TK2MSFTNGP09.phx.gbl>

<sA**************@cpmsftngxa06.phx.gbl>
>Subject: Re: Thread Name
>Date: Mon, 3 Nov 2003 17:43:38 -0500
>Lines: 30
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>Message-ID: <uY**************@tk2msftngp13.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: dhcp16624016.indy.rr.com 24.166.24.16
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:153330
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb
>
>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.
>>
>
>
>



Nov 20 '05 #7

P: n/a
Here are the two methods. The application.run is required by the Intel CT
ADE com interop object.

Friend Sub Thread_TrunkA_Start()
'create new instance of thread
Dim Trunk_Thread As Thread

' set thread equal to delegate (i.e. method to start at)
Trunk_Thread = New Thread(AddressOf Thread_TrunkB)

' 11/03 If you use "Trunk_Thread.Name = xxx" , the name exists until
"Application.Run" in delegate (i.e. addressOf) and then is nothing after
that for the rest of the thread. If you use the format
"Thread.CurrentThread.Name = xxx" the thread name is nothing before
"Application.Run" but then correct in the rest of the thread.
'give each thread a unique name (for later identification)
Thread.CurrentThread.Name = Format(Me.m_This_Trunk_0_Based, "000") &
"_Trunk_Thread_0_Based"

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

' start thread instance
Trunk_Thread.Start()
End Sub

Public Sub Thread_TrunkB()
' Purpose: This is the delegate (ie addressOf method)where thread starts;
each thread represent one telephone line. This method Assigns a trunk to
this thread and waits for an Incoming call event to happen; You MUST assign
trunks in the same FileName document that you use the Incoming_Call handler.

' Assigns this trunk (zero based, 1st trunk is 0)
' execute Intel CT ADE telephony command
Telephony.TrunkAssign(m_This_Trunk_0_Based)

' Start message loop. This allows Intel CT ADE to fire events to the sub
incoming call handler. Note on RUN line that processing stops and waits for
an event (like incoming call)
Application.Run()

End Sub

Thanks!
Bob Day
"Peter Huang" <v-******@online.microsoft.com> wrote in message
news:yK**************@cpmsftngxa06.phx.gbl...
Hi Bob,

I am sorry, but I am not very clear about the problem.
Based on my understanding, you are using VB.NET windows application.
But where do you call the Application.Run method, can you post a simple
sample as long as it can demostrate the problem.
I will be appreciate your efforts.

I look forward to hearing from.
td.Name = "TestThread"
with
thread.currentthread.name = "TestThread"

It seems that you set the thread's name in a already running thread.
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.
--------------------
From: "Bob Day" <Bo****@TouchTalk.net>
References: <OH**************@TK2MSFTNGP09.phx.gbl>

<sA**************@cpmsftngxa06.phx.gbl>
<uY**************@tk2msftngp13.phx.gbl>
<Ik*************@cpmsftngxa06.phx.gbl>
Subject: Re: Thread Name disappears after "Application.Run"
Date: Tue, 4 Nov 2003 15:23:07 -0500
Lines: 113
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <eO**************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: dhcp16624016.indy.rr.com 24.166.24.16
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:153626
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

OK, followed your code exactly, and I think I see where the problem is.

The
delegate (i.e. addressOf method) ends with the statement "Application.Run"
since the entire thread is based on a Intel CTADE com object. Following
your code below, the thread name exists before "Application.Run", and
becomes nothing in all methods in the thread after that. I have no idea
why.

As a work around, I replaced your line:
td.Name = "TestThread"
with
thread.currentthread.name = "TestThread"

With that change, immediately before "Application.Run" the name is nothing,but after "Application.Run" the name is correct ( i.e. "TestThread") in anymethod in the tread.

Any ideas? It seems to work, so I will go with it for a while.

Thanks for the code you wrote.

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

Here is my code, you may have a try.

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim o As New TestThread
o.ThreadRun()
End Sub

Public Class TestThread
Dim td As Thread
Public Sub New()
' if the three line is moved to the ThreadRun, it works too.
td = New Thread(AddressOf hello)
td.Name = "TestThread"
td.ApartmentState = ApartmentState.STA
End Sub
Public Shared Sub hello()
Debug.WriteLine(Thread.CurrentThread.Name)
End Sub
Public Sub ThreadRun()
td.Start()
End Sub
End Class

Or can you post your code for us to reproduce the problem.

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. --------------------
>From: "Bob Day" <Bo****@TouchTalk.net>
>References: <OH**************@TK2MSFTNGP09.phx.gbl>
<sA**************@cpmsftngxa06.phx.gbl>
>Subject: Re: Thread Name
>Date: Mon, 3 Nov 2003 17:43:38 -0500
>Lines: 30
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
>Message-ID: <uY**************@tk2msftngp13.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.vb
>NNTP-Posting-Host: dhcp16624016.indy.rr.com 24.166.24.16
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:153330
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb
>
>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.
>>
>
>
>


Nov 20 '05 #8

P: n/a
Hi Bob,

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim o As New TestThread
o.ThreadRun()
End Sub
Public Class TestThread
Dim td As Thread
Public Sub New()
td = New Thread(AddressOf hello)
td.Name = "TestThread"
td.ApartmentState = ApartmentState.STA
End Sub
Public Shared Sub hello()
Debug.WriteLine(Thread.CurrentThread.Name)
Application.Run(New Form1)
Debug.WriteLine(Thread.CurrentThread.Name)
End Sub
Public Sub ThreadRun()
td.Start()
End Sub
End Class
=============================================
Debug.WriteLine(Thread.CurrentThread.Name)
Application.Run(New Form1)
Debug.WriteLine(Thread.CurrentThread.Name)
=============================================
The three code lines are in same thread so they will all get the right name
of the thread.("TestThread")


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.
--------------------
From: "Bob Day" <Bo****@TouchTalk.net>
References: <OH**************@TK2MSFTNGP09.phx.gbl> <sA**************@cpmsftngxa06.phx.gbl>
<uY**************@tk2msftngp13.phx.gbl>
<Ik*************@cpmsftngxa06.phx.gbl>
<eO**************@TK2MSFTNGP11.phx.gbl>
<yK**************@cpmsftngxa06.phx.gbl>Subject: Re: Thread Name disappears after "Application.Run"
Date: Wed, 5 Nov 2003 13:38:38 -0500
Lines: 213
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#h**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: dhcp065-029-072-036.indy.rr.com 65.29.72.36
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:153960
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Here are the two methods. The application.run is required by the Intel CT
ADE com interop object.

Friend Sub Thread_TrunkA_Start()
'create new instance of thread
Dim Trunk_Thread As Thread

' set thread equal to delegate (i.e. method to start at)
Trunk_Thread = New Thread(AddressOf Thread_TrunkB)

' 11/03 If you use "Trunk_Thread.Name = xxx" , the name exists until
"Application.Run" in delegate (i.e. addressOf) and then is nothing after
that for the rest of the thread. If you use the format
"Thread.CurrentThread.Name = xxx" the thread name is nothing before
"Application.Run" but then correct in the rest of the thread. I do not know which code lines do you mean is the rest of the
thread.(Thread_TrunkB)
What the life of Thread_TrunkB is between Public Sub Thread_TrunkB() and End Sub
That is to say if new thread has gone to the end of the "End Sub",(after
the Application.Run), the thread is gone away.
Now if you call the Thread.CurrentThread.Name, you will get another
thread's name.
I think you may try to look on the thread function(Thread_TrunkB) as an
function running in another thread, if the function has ended, the new
thread will end.
You may try to refer to the topic in MSDN.
Thread Class
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemThreadingThreadClassTopic.asp

'give each thread a unique name (for later identification)
Thread.CurrentThread.Name = Format(Me.m_This_Trunk_0_Based, "000") &
"_Trunk_Thread_0_Based"

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

' start thread instance
Trunk_Thread.Start()
End Sub

Public Sub Thread_TrunkB()
' Purpose: This is the delegate (ie addressOf method)where thread starts;each thread represent one telephone line. This method Assigns a trunk to
this thread and waits for an Incoming call event to happen; You MUST assigntrunks in the same FileName document that you use the Incoming_Call handler.
' Assigns this trunk (zero based, 1st trunk is 0)
' execute Intel CT ADE telephony command
Telephony.TrunkAssign(m_This_Trunk_0_Based)

' Start message loop. This allows Intel CT ADE to fire events to the sub
incoming call handler. Note on RUN line that processing stops and waits foran event (like incoming call)
Application.Run()

End Sub

Thanks!
Bob Day


Nov 20 '05 #9

P: n/a
Again, followed your instructions exactly, but get different results.

1) In sub new, after thread lines like
gtThread_Trunk.Name = Format(Me.m_This_Trunk_0_Based, "000") &
"_Trunk_Thread_0_Based")

' x shows name, x1 nothing

Dim x As String = Me.gtThread_Trunk.Name

Dim x1 As String = Thread.CurrentThread.Name

2) after gtThread_Trunk.start, but Immediately before application.run

' x & x1 show name

Dim x As String = Me.gtThread_Trunk.Name ' Thread.CurrentThread.Name

Dim x1 As String = Thread.CurrentThread.Name

3) After Application.run

'x shows name, x1 shows nothing

Dim x As String = Me.gtThread_Trunk.Name

Dim x1 As String = Thread.CurrentThread.Name

It is not clear to me why these return different results, I would think at
any point after thread.start they would return the same.

Anyway, I no see how to get the thread name using gtThread_Trunk.Name
instead of Thread.CurrentThread.Name, so this work around is fine with me.

Thanks for all your help. Would be interested in you comments if you have
any idea what is happening.

Bob Day

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

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim o As New TestThread
o.ThreadRun()
End Sub
Public Class TestThread
Dim td As Thread
Public Sub New()
td = New Thread(AddressOf hello)
td.Name = "TestThread"
td.ApartmentState = ApartmentState.STA
End Sub
Public Shared Sub hello()
Debug.WriteLine(Thread.CurrentThread.Name)
Application.Run(New Form1)
Debug.WriteLine(Thread.CurrentThread.Name)
End Sub
Public Sub ThreadRun()
td.Start()
End Sub
End Class
=============================================
Debug.WriteLine(Thread.CurrentThread.Name)
Application.Run(New Form1)
Debug.WriteLine(Thread.CurrentThread.Name)
=============================================
The three code lines are in same thread so they will all get the right name of the thread.("TestThread")


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.
--------------------
From: "Bob Day" <Bo****@TouchTalk.net>
References: <OH**************@TK2MSFTNGP09.phx.gbl> <sA**************@cpmsftngxa06.phx.gbl>
<uY**************@tk2msftngp13.phx.gbl>
<Ik*************@cpmsftngxa06.phx.gbl>
<eO**************@TK2MSFTNGP11.phx.gbl>
<yK**************@cpmsftngxa06.phx.gbl>
Subject: Re: Thread Name disappears after "Application.Run"
Date: Wed, 5 Nov 2003 13:38:38 -0500
Lines: 213
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#h**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: dhcp065-029-072-036.indy.rr.com 65.29.72.36
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:153960
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Here are the two methods. The application.run is required by the Intel CTADE com interop object.

Friend Sub Thread_TrunkA_Start()
'create new instance of thread
Dim Trunk_Thread As Thread

' set thread equal to delegate (i.e. method to start at)
Trunk_Thread = New Thread(AddressOf Thread_TrunkB)

' 11/03 If you use "Trunk_Thread.Name = xxx" , the name exists until
"Application.Run" in delegate (i.e. addressOf) and then is nothing after
that for the rest of the thread. If you use the format
"Thread.CurrentThread.Name = xxx" the thread name is nothing before
"Application.Run" but then correct in the rest of the thread.

I do not know which code lines do you mean is the rest of the
thread.(Thread_TrunkB)
What the life of Thread_TrunkB is between
Public Sub Thread_TrunkB()

and
End Sub


That is to say if new thread has gone to the end of the "End Sub",(after
the Application.Run), the thread is gone away.
Now if you call the Thread.CurrentThread.Name, you will get another
thread's name.
I think you may try to look on the thread function(Thread_TrunkB) as an
function running in another thread, if the function has ended, the new
thread will end.
You may try to refer to the topic in MSDN.
Thread Class

http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfSystemThreadingThreadClassTopic.asp

'give each thread a unique name (for later identification)
Thread.CurrentThread.Name = Format(Me.m_This_Trunk_0_Based, "000") &
"_Trunk_Thread_0_Based"

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

' start thread instance
Trunk_Thread.Start()
End Sub

Public Sub Thread_TrunkB()
' Purpose: This is the delegate (ie addressOf method)where thread

starts;
each thread represent one telephone line. This method Assigns a trunk to
this thread and waits for an Incoming call event to happen; You MUST

assign
trunks in the same FileName document that you use the Incoming_Call

handler.

' Assigns this trunk (zero based, 1st trunk is 0)
' execute Intel CT ADE telephony command
Telephony.TrunkAssign(m_This_Trunk_0_Based)

' Start message loop. This allows Intel CT ADE to fire events to the subincoming call handler. Note on RUN line that processing stops and waits

for
an event (like incoming call)
Application.Run()

End Sub

Thanks!
Bob Day


Nov 20 '05 #10

P: n/a
Hi Bob,

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim o As New TestThread
o.ThreadRun()
End Sub
Public Class TestThread
Dim td As Thread
Public Sub New()
td = New Thread(AddressOf hello)
td.Name = "TestThread"
td.ApartmentState = ApartmentState.STA
End Sub
Public Shared Sub hello()
Debug.WriteLine(Thread.CurrentThread.Name) '[A]
Application.Run(New Form1)
End Sub
Public Sub ThreadRun()
td.Start()
Debug.WriteLine(Thread.CurrentThread.Name) '[b]
End Sub
End Class
Did my code do what you are doing?
If so, I think the [A] and [b] are in different thread.

the [b] is in the main thread in which you call the ThreadRun.
While [A} is in the new started thread.
If that is not what you mean, please change my code to demostrate your
meaning.
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.
--------------------
From: "Bob Day" <Bo****@TouchTalk.net>
References: <OH**************@TK2MSFTNGP09.phx.gbl> <sA**************@cpmsftngxa06.phx.gbl>
<uY**************@tk2msftngp13.phx.gbl>
<Ik*************@cpmsftngxa06.phx.gbl>
<eO**************@TK2MSFTNGP11.phx.gbl>
<yK**************@cpmsftngxa06.phx.gbl>
<#h**************@TK2MSFTNGP10.phx.gbl>
<cn**************@cpmsftngxa06.phx.gbl>Subject: Re: Thread Name disappears after "Application.Run"
Date: Thu, 6 Nov 2003 15:07:03 -0500
Lines: 185
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#P*************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: dhcp065-029-072-036.indy.rr.com 65.29.72.36
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:154501
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Again, followed your instructions exactly, but get different results.

1) In sub new, after thread lines like
gtThread_Trunk.Name = Format(Me.m_This_Trunk_0_Based, "000") &
"_Trunk_Thread_0_Based")

' x shows name, x1 nothing

Dim x As String = Me.gtThread_Trunk.Name

Dim x1 As String = Thread.CurrentThread.Name

2) after gtThread_Trunk.start, but Immediately before application.run

' x & x1 show name

Dim x As String = Me.gtThread_Trunk.Name ' Thread.CurrentThread.Name

Dim x1 As String = Thread.CurrentThread.Name

3) After Application.run

'x shows name, x1 shows nothing

Dim x As String = Me.gtThread_Trunk.Name

Dim x1 As String = Thread.CurrentThread.Name

It is not clear to me why these return different results, I would think at
any point after thread.start they would return the same.

Anyway, I no see how to get the thread name using gtThread_Trunk.Name
instead of Thread.CurrentThread.Name, so this work around is fine with me.

Thanks for all your help. Would be interested in you comments if you have
any idea what is happening.

Bob Day


Nov 20 '05 #11

P: n/a
Hi Bob,

If your results are different to those expected, something has to be causing it. If you package up that project, we can
confirm whether it's in the project or in your system.

Can you set the name of this nameless thread after Application.Run? It's a write-once property so should fall over if
you try.

Have you tried
If Not Me.gtThread_Trunk Is Thread.CurrentThread Then
MsgBox ("Hell's Bells!")
End If
after Application.Run?

Is your testbed still using that Intel object? Could this be doing something like invoking a delegate in a different
Thread?

Regards,
Fergus

Nov 20 '05 #12

P: n/a

After application run, here is the results:
If Not Me.gcThread_Trunk Is Thread.CurrentThread Then

' x = nothing, x1 = thread name

Dim x As String = Thread.CurrentThread.Name

Dim x1 As String = Me.gcThread_Trunk.Name

End If

How can X be nothing? It must be some thread, with some name, or if you
don't name a thread will it show nothing?

X 1 = 000_thread_Trunk_0_Based (ie thread name in 3 positions below):

After me.gcThread_Trunk.start, x = nothing, which makes sense.

Before Application Run, x = the new threads name, which makes sense.

After Application run, x = nothing again, which does not make sense.

I will runs some tests to see if I can comeup with any other info.

Thanks!

Bob Day
"Fergus Cooney" <fi****@post.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi Bob,

If your results are different to those expected, something has to be causing it. If you package up that project, we can confirm whether it's in the project or in your system.

Can you set the name of this nameless thread after Application.Run? It's a write-once property so should fall over if you try.

Have you tried
If Not Me.gtThread_Trunk Is Thread.CurrentThread Then
MsgBox ("Hell's Bells!")
End If
after Application.Run?

Is your testbed still using that Intel object? Could this be doing something like invoking a delegate in a different Thread?

Regards,
Fergus

Nov 20 '05 #13

P: n/a
Hi Bob,

The project's behavior seems like the code after Application.Run
Dim x As String = Thread.CurrentThread.Name seems to return to the first
thread, so the result is same as the first one.
Have you tried to run my code for a test, or modify my code to reproduce
the problem?
If you have concern on this object please post here.
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.
--------------------
From: "Bob Day" <Bo****@TouchTalk.net>
References: <OH**************@TK2MSFTNGP09.phx.gbl> <sA**************@cpmsftngxa06.phx.gbl>
<uY**************@tk2msftngp13.phx.gbl>
<Ik*************@cpmsftngxa06.phx.gbl>
<eO**************@TK2MSFTNGP11.phx.gbl>
<yK**************@cpmsftngxa06.phx.gbl>
<#h**************@TK2MSFTNGP10.phx.gbl>
<cn**************@cpmsftngxa06.phx.gbl>
<#P*************@TK2MSFTNGP10.phx.gbl>
<#q**************@TK2MSFTNGP12.phx.gbl>Subject: Re: Thread Name disappears after "Application.Run"
Date: Mon, 10 Nov 2003 14:12:30 -0500
Lines: 59
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#v**************@TK2MSFTNGP12.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: dhcp065-029-072-102.indy.rr.com 65.29.72.102
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:155623
X-Tomcat-NG: microsoft.public.dotnet.languages.vb
After application run, here is the results:
If Not Me.gcThread_Trunk Is Thread.CurrentThread Then

' x = nothing, x1 = thread name

Dim x As String = Thread.CurrentThread.Name

Dim x1 As String = Me.gcThread_Trunk.Name

End If

How can X be nothing? It must be some thread, with some name, or if you
don't name a thread will it show nothing?

X 1 = 000_thread_Trunk_0_Based (ie thread name in 3 positions below):

After me.gcThread_Trunk.start, x = nothing, which makes sense.

Before Application Run, x = the new threads name, which makes sense.

After Application run, x = nothing again, which does not make sense.

I will runs some tests to see if I can comeup with any other info.

Thanks!

Bob Day
"Fergus Cooney" <fi****@post.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi Bob,

If your results are different to those expected, something has to be

causing it. If you package up that project, we can
confirm whether it's in the project or in your system.

Can you set the name of this nameless thread after Application.Run?

It's a write-once property so should fall over if
you try.

Have you tried
If Not Me.gtThread_Trunk Is Thread.CurrentThread Then
MsgBox ("Hell's Bells!")
End If
after Application.Run?

Is your testbed still using that Intel object? Could this be doing

something like invoking a delegate in a different
Thread?

Regards,
Fergus



Nov 20 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.