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 13 4982
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
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.
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 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.
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. >> > > >
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. 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
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. >> > > >
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
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 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
subincoming call handler. Note on RUN line that processing stops and waits
foran event (like incoming call) Application.Run()
End Sub
Thanks! Bob Day
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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?
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |