473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Thread Name

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
13 5027
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
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
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
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
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
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
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
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
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
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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not...
4
by: Leonardo Hyppolito | last post by:
Hello, I am trying to write a multithread program that simulates producers and consumers. My program can have many producers and many consumers (each in a separate thread). It has a storage...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
1
by: scorpion53061 | last post by:
I have MS Word operating in a thread other than the main writing a report. Can I tell the main thread to wait until a particular point (a sub starts) in another thread before continuing on?
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
5
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I...
5
by: taylorjonl | last post by:
I am completely baffled. I am writting a daemon application for my work to save me some time. The application works fine at my home but won't work right here at work. Basically I have a...
6
by: seb | last post by:
Hi, I am using pygtk for the first times. I am wondering what would be the best "pattern" to interface pygtk with a thread. The thread is collecting informations (over the network for...
8
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I have an application with several BackgroundWorker threads. I hoped I'd be able to just type backgroundworker1.Name = "bw1"; but I don't see a name property. Any thoughts on how to name a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.