473,698 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading

Hi all,

I have a need for a STA thread from asp.net. I can create the thread and it
runs fine. But when it is finished, the thread still 'hangs' arround.
Visible only to the debugger.....
I get the "The thread has exited with code 0 (0x12fc)." in the debugger
each time the thread seemly end, but its still there in the thread window.
GC.Collect() does not get rid of them either, something must be holding a
reference to the threads........ .
a trivial example that demonstrates this

public void Work()
{
Thread.Sleep( 5000 ) ;
System.Diagnost ics.Debug.Write Line("Done!");
}

private void Button1_Click(o bject sender, System.EventArg s e)
{
ThreadStart ts = new ThreadStart( Work ) ;
Thread t = new Thread( ts );
t.Name = "test";
t.Start();
t.Join();
Debug.WriteLine ( Process.GetCurr entProcess().Th reads.Count );
t = null ;
GC.Collect();
}
Is there anyway to clean up the Thread?

Dec 16 '05 #1
9 1747
GC.Collect() doesn't clean everything up. You might want to wait around and
see if it gets cleaned up eventually. Otherwise, unless you have some reason
to think that it won't get cleaned up (such as interop being used in the
thread, and you're not sure that the Interop classes are being disposed
correctly), just trust the Framework.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"AdrianJMar tin" <Ad***********@ newsgroups.nosp am> wrote in message
news:OI******** *****@tk2msftng p13.phx.gbl...
Hi all,

I have a need for a STA thread from asp.net. I can create the thread and
it runs fine. But when it is finished, the thread still 'hangs' arround.
Visible only to the debugger.....
I get the "The thread has exited with code 0 (0x12fc)." in the debugger
each time the thread seemly end, but its still there in the thread window.
GC.Collect() does not get rid of them either, something must be holding a
reference to the threads........ .
a trivial example that demonstrates this

public void Work()
{
Thread.Sleep( 5000 ) ;
System.Diagnost ics.Debug.Write Line("Done!");
}

private void Button1_Click(o bject sender, System.EventArg s e)
{
ThreadStart ts = new ThreadStart( Work ) ;
Thread t = new Thread( ts );
t.Name = "test";
t.Start();
t.Join();
Debug.WriteLine ( Process.GetCurr entProcess().Th reads.Count );
t = null ;
GC.Collect();
}
Is there anyway to clean up the Thread?

Dec 16 '05 #2
If the execution of Button1_Click makes it past the call to Thread.Join
then the thread definitely terminated. The debugger may not be
refreshing the thread window correctly.

AdrianJMartin wrote:
Hi all,

I have a need for a STA thread from asp.net. I can create the thread and it
runs fine. But when it is finished, the thread still 'hangs' arround.
Visible only to the debugger.....
I get the "The thread has exited with code 0 (0x12fc)." in the debugger
each time the thread seemly end, but its still there in the thread window.
GC.Collect() does not get rid of them either, something must be holding a
reference to the threads........ .
a trivial example that demonstrates this

public void Work()
{
Thread.Sleep( 5000 ) ;
System.Diagnost ics.Debug.Write Line("Done!");
}

private void Button1_Click(o bject sender, System.EventArg s e)
{
ThreadStart ts = new ThreadStart( Work ) ;
Thread t = new Thread( ts );
t.Name = "test";
t.Start();
t.Join();
Debug.WriteLine ( Process.GetCurr entProcess().Th reads.Count );
t = null ;
GC.Collect();
}
Is there anyway to clean up the Thread?


Dec 16 '05 #3
I see no reason for STA thread based on the example you provided. Care to
elaborate? STA threads are for COM based process by the way.

sorry, scratch that. I realized you were simply using incorrect terminology.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"AdrianJMar tin" <Ad***********@ newsgroups.nosp am> wrote in message
news:OI******** *****@tk2msftng p13.phx.gbl...
Hi all,

I have a need for a STA thread from asp.net. I can create the thread and it runs fine. But when it is finished, the thread still 'hangs' arround.
Visible only to the debugger.....
I get the "The thread has exited with code 0 (0x12fc)." in the debugger
each time the thread seemly end, but its still there in the thread window.
GC.Collect() does not get rid of them either, something must be holding a
reference to the threads........ .
a trivial example that demonstrates this

public void Work()
{
Thread.Sleep( 5000 ) ;
System.Diagnost ics.Debug.Write Line("Done!");
}

private void Button1_Click(o bject sender, System.EventArg s e)
{
ThreadStart ts = new ThreadStart( Work ) ;
Thread t = new Thread( ts );
t.Name = "test";
t.Start();
t.Join();
Debug.WriteLine ( Process.GetCurr entProcess().Th reads.Count );
t = null ;
GC.Collect();
}
Is there anyway to clean up the Thread?

Dec 16 '05 #4
I DO need an STA thread, I'm creating an invisible window that hosts mshtml
and axwebrowser. I'm dynamically creating a bitmap using html. I need some
consistancy across platforms, I have this code working fine. But I have to
create a thread(STA) to host it.

In my testing i've noticed that the thread hangs arround in the debugger.
Even stripping my component out and creating the do almost nothing thread
example that i posted leaves this 'orphaned' thread. Regardless of the
apartment state.

I can't use the threadpool as the those threads are always MTA.
"Alvin Bruney - ASP.NET MVP" <www.lulu.com/owc> wrote in message
news:ez******** ******@TK2MSFTN GP11.phx.gbl...
I see no reason for STA thread based on the example you provided. Care to
elaborate? STA threads are for COM based process by the way.

sorry, scratch that. I realized you were simply using incorrect
terminology.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"AdrianJMar tin" <Ad***********@ newsgroups.nosp am> wrote in message
news:OI******** *****@tk2msftng p13.phx.gbl...
Hi all,

I have a need for a STA thread from asp.net. I can create the thread and

it
runs fine. But when it is finished, the thread still 'hangs' arround.
Visible only to the debugger.....
I get the "The thread has exited with code 0 (0x12fc)." in the debugger
each time the thread seemly end, but its still there in the thread
window.
GC.Collect() does not get rid of them either, something must be holding a
reference to the threads........ .
a trivial example that demonstrates this

public void Work()
{
Thread.Sleep( 5000 ) ;
System.Diagnost ics.Debug.Write Line("Done!");
}

private void Button1_Click(o bject sender, System.EventArg s e)
{
ThreadStart ts = new ThreadStart( Work ) ;
Thread t = new Thread( ts );
t.Name = "test";
t.Start();
t.Join();
Debug.WriteLine ( Process.GetCurr entProcess().Th reads.Count );
t = null ;
GC.Collect();
}
Is there anyway to clean up the Thread?


Dec 19 '05 #5
Hi Adrian,

If the hang or unreleased thread you watched is the underlying operating
system thread, then that should be reasonable since regardless of the
thread operation (start, end,.....), the CLR's unmanaged code has structure
to hold reference to operating system thread. And so there is no definite
mapping between the underlying operating system thread to the managed CLR
thread instance..... Sometimes, our CLR t hread's work has finished, the
underlying CLR structure may still hold the OS thread. Or other times event
the OS thread has destroyed, the CLR's thread reference still refer to a
managed thread object (for keepting some thread information.... )...

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "AdrianJMar tin" <Ad***********@ newsgroups.nosp am>
| References: <OI************ *@tk2msftngp13. phx.gbl>
<ez************ **@TK2MSFTNGP11 .phx.gbl>
| Subject: Re: Threading
| Date: Mon, 19 Dec 2005 09:43:27 -0000
| Lines: 77
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <OQ************ *@TK2MSFTNGP12. phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ip-217-204-53-234.easynet.co. uk 217.204.53.234
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3656 58
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| I DO need an STA thread, I'm creating an invisible window that hosts
mshtml
| and axwebrowser. I'm dynamically creating a bitmap using html. I need
some
| consistancy across platforms, I have this code working fine. But I have
to
| create a thread(STA) to host it.
|
| In my testing i've noticed that the thread hangs arround in the debugger.
| Even stripping my component out and creating the do almost nothing thread
| example that i posted leaves this 'orphaned' thread. Regardless of the
| apartment state.
|
| I can't use the threadpool as the those threads are always MTA.
|
|
| "Alvin Bruney - ASP.NET MVP" <www.lulu.com/owc> wrote in message
| news:ez******** ******@TK2MSFTN GP11.phx.gbl...
| >I see no reason for STA thread based on the example you provided. Care to
| > elaborate? STA threads are for COM based process by the way.
| >
| > sorry, scratch that. I realized you were simply using incorrect
| > terminology.
| >
| > --
| > Regards,
| > Alvin Bruney [MVP ASP.NET]
| >
| > [Shameless Author plug]
| > The Microsoft Office Web Components Black Book with .NET
| > Now Available @ www.lulu.com/owc
| > Forth-coming VSTO.NET - Wrox/Wiley 2006
| > -------------------------------------------------------
| >
| >
| >
| > "AdrianJMar tin" <Ad***********@ newsgroups.nosp am> wrote in message
| > news:OI******** *****@tk2msftng p13.phx.gbl...
| >> Hi all,
| >>
| >> I have a need for a STA thread from asp.net. I can create the thread
and
| > it
| >> runs fine. But when it is finished, the thread still 'hangs' arround.
| >> Visible only to the debugger.....
| >> I get the "The thread has exited with code 0 (0x12fc)." in the
debugger
| >> each time the thread seemly end, but its still there in the thread
| >> window.
| >> GC.Collect() does not get rid of them either, something must be
holding a
| >> reference to the threads........ .
| >>
| >>
| >> a trivial example that demonstrates this
| >>
| >> public void Work()
| >> {
| >> Thread.Sleep( 5000 ) ;
| >> System.Diagnost ics.Debug.Write Line("Done!");
| >> }
| >>
| >> private void Button1_Click(o bject sender, System.EventArg s e)
| >> {
| >> ThreadStart ts = new ThreadStart( Work ) ;
| >> Thread t = new Thread( ts );
| >> t.Name = "test";
| >> t.Start();
| >> t.Join();
| >> Debug.WriteLine ( Process.GetCurr entProcess().Th reads.Count );
| >> t = null ;
| >> GC.Collect();
| >> }
| >>
| >>
| >> Is there anyway to clean up the Thread?
| >>
| >>
| >>
| >
| >
|
|
|

Dec 20 '05 #6
Hi Steven,

Why would it be an OS thread I see? VS debugging is set to Managed only, and
I've name the thread. if you run the code below, press the button a few
times, snap on a debugger break point inside Button1_Click(. ..) and see that
thread window is full of orphaned threads.( you may have Comment out the
t.Join )
Adrian


"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:jk******** ******@TK2MSFTN GXA02.phx.gbl.. .
Hi Adrian,

If the hang or unreleased thread you watched is the underlying operating
system thread, then that should be reasonable since regardless of the
thread operation (start, end,.....), the CLR's unmanaged code has
structure
to hold reference to operating system thread. And so there is no definite
mapping between the underlying operating system thread to the managed CLR
thread instance..... Sometimes, our CLR t hread's work has finished, the
underlying CLR structure may still hold the OS thread. Or other times
event
the OS thread has destroyed, the CLR's thread reference still refer to a
managed thread object (for keepting some thread information.... )...

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "AdrianJMar tin" <Ad***********@ newsgroups.nosp am>
| References: <OI************ *@tk2msftngp13. phx.gbl>
<ez************ **@TK2MSFTNGP11 .phx.gbl>
| Subject: Re: Threading
| Date: Mon, 19 Dec 2005 09:43:27 -0000
| Lines: 77
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <OQ************ *@TK2MSFTNGP12. phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ip-217-204-53-234.easynet.co. uk 217.204.53.234
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3656 58
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| I DO need an STA thread, I'm creating an invisible window that hosts
mshtml
| and axwebrowser. I'm dynamically creating a bitmap using html. I need
some
| consistancy across platforms, I have this code working fine. But I have
to
| create a thread(STA) to host it.
|
| In my testing i've noticed that the thread hangs arround in the
debugger.
| Even stripping my component out and creating the do almost nothing
thread
| example that i posted leaves this 'orphaned' thread. Regardless of the
| apartment state.
|
| I can't use the threadpool as the those threads are always MTA.
|
|
| "Alvin Bruney - ASP.NET MVP" <www.lulu.com/owc> wrote in message
| news:ez******** ******@TK2MSFTN GP11.phx.gbl...
| >I see no reason for STA thread based on the example you provided. Care
to
| > elaborate? STA threads are for COM based process by the way.
| >
| > sorry, scratch that. I realized you were simply using incorrect
| > terminology.
| >
| > --
| > Regards,
| > Alvin Bruney [MVP ASP.NET]
| >
| > [Shameless Author plug]
| > The Microsoft Office Web Components Black Book with .NET
| > Now Available @ www.lulu.com/owc
| > Forth-coming VSTO.NET - Wrox/Wiley 2006
| > -------------------------------------------------------
| >
| >
| >
| > "AdrianJMar tin" <Ad***********@ newsgroups.nosp am> wrote in message
| > news:OI******** *****@tk2msftng p13.phx.gbl...
| >> Hi all,
| >>
| >> I have a need for a STA thread from asp.net. I can create the thread
and
| > it
| >> runs fine. But when it is finished, the thread still 'hangs' arround.
| >> Visible only to the debugger.....
| >> I get the "The thread has exited with code 0 (0x12fc)." in the
debugger
| >> each time the thread seemly end, but its still there in the thread
| >> window.
| >> GC.Collect() does not get rid of them either, something must be
holding a
| >> reference to the threads........ .
| >>
| >>
| >> a trivial example that demonstrates this
| >>
| >> public void Work()
| >> {
| >> Thread.Sleep( 5000 ) ;
| >> System.Diagnost ics.Debug.Write Line("Done!");
| >> }
| >>
| >> private void Button1_Click(o bject sender, System.EventArg s e)
| >> {
| >> ThreadStart ts = new ThreadStart( Work ) ;
| >> Thread t = new Thread( ts );
| >> t.Name = "test";
| >> t.Start();
| >> t.Join();
| >> Debug.WriteLine ( Process.GetCurr entProcess().Th reads.Count );
| >> t = null ;
| >> GC.Collect();
| >> }
| >>
| >>
| >> Is there anyway to clean up the Thread?
| >>
| >>
| >>
| >
| >
|
|
|

Dec 20 '05 #7
Hi Adrian,

Thanks for your quick response.
For the Process.GetCurr entProcess().Th reads, it's a collection that
represents all the OS threads in the current running process(retriev e from
server's performance counter), we can see that the Thread's class is
"ProcessThr ead" rather than the System.Threadin g.Thread.....

Also, based on my local test, when creating a new thread that in STA
apartment model, it'll end successfully (the OS thread will also be
destoryed....). And for the .net's managed Thread class, it's threadState
will be set to "Stoped" when it has finished the work, we no longer need to
worry about the sequential work since the CLR will take care of it.....

Here is a test page I used to print the process threads and the managed
threads (I manually created)'s status......

I contains three buttons , one used to printout OS threads, one used to
create new STA threads, and the third print out my managed threads:

=============== ==============
public class ThreadTest : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Butt on btnPrintThreads ;
protected System.Web.UI.W ebControls.Butt on btnStartThreads ;
protected System.Web.UI.W ebControls.Butt on btnPrintManaged Threads;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.btnPrintTh reads.Click += new
System.EventHan dler(this.btnPr intThreads_Clic k);
this.btnStartTh reads.Click += new
System.EventHan dler(this.btnSt artThreads_Clic k);
this.btnPrintMa nagedThreads.Cl ick += new
System.EventHan dler(this.btnPr intManagedThrea ds_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void btnStartThreads _Click(object sender, System.EventArg s e)
{
Thread td = new Thread(new ThreadStart(Wor k));

if(Application["threads"] == null)
{
Application["threads"] = new ArrayList();
}

ArrayList list = Application["threads"] as ArrayList;

list.Add(td);

td.ApartmentSta te = ApartmentState. STA;
td.Start();

}

private void btnPrintThreads _Click(object sender, System.EventArg s e)
{
Response.Write( "<br>========== ========");
Response.Write( "<br>OS threads: " +
Process.GetCurr entProcess().Th reads.Count);

foreach(Process Thread pt in Process.GetCurr entProcess().Th reads)
{
Response.Write( "<br>Id: " + pt.Id + " Status: " + pt.ThreadState) ;
}
}

private void btnPrintManaged Threads_Click(o bject sender, System.EventArg s
e)
{
if(Application["threads"] == null)
{
Application["threads"] = new ArrayList();
}

ArrayList list = Application["threads"] as ArrayList;

Response.Write( "<br>%%%%%%%%%% %%%%%%%%%%%%%%% %%%%%%");
Response.Write( "<br>Worker Threads: " + list.Count);

foreach(object obj in list)
{
Thread td = obj as Thread;
if(td != null)
{
Response.Write( "<br>Id: " + td.Name + " status: " + td.ThreadState) ;
}
}
}
public static void Work()
{
Thread.Sleep( 10000 ) ;
System.Diagnost ics.Debug.Write Line("Done!");
}
}
=============== =============

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "AdrianJMar tin" <Ad***********@ newsgroups.nosp am>
| References: <OI************ *@tk2msftngp13. phx.gbl>
<ez************ **@TK2MSFTNGP11 .phx.gbl>
<OQ************ *@TK2MSFTNGP12. phx.gbl>
<jk************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: Re: Threading
| Date: Tue, 20 Dec 2005 09:49:04 -0000
| Lines: 153
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <eG************ **@TK2MSFTNGP14 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ip-217-204-53-234.easynet.co. uk 217.204.53.234
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP14.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3659 06
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Hi Steven,
|
| Why would it be an OS thread I see? VS debugging is set to Managed only,
and
| I've name the thread. if you run the code below, press the button a few
| times, snap on a debugger break point inside Button1_Click(. ..) and see
that
| thread window is full of orphaned threads.( you may have Comment out the
| t.Join )
|
|
| Adrian
|
|
|
|
|
|
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:jk******** ******@TK2MSFTN GXA02.phx.gbl.. .
| > Hi Adrian,
| >
| > If the hang or unreleased thread you watched is the underlying operating
| > system thread, then that should be reasonable since regardless of the
| > thread operation (start, end,.....), the CLR's unmanaged code has
| > structure
| > to hold reference to operating system thread. And so there is no
definite
| > mapping between the underlying operating system thread to the managed
CLR
| > thread instance..... Sometimes, our CLR t hread's work has finished, the
| > underlying CLR structure may still hold the OS thread. Or other times
| > event
| > the OS thread has destroyed, the CLR's thread reference still refer to a
| > managed thread object (for keepting some thread information.... )...
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | From: "AdrianJMar tin" <Ad***********@ newsgroups.nosp am>
| > | References: <OI************ *@tk2msftngp13. phx.gbl>
| > <ez************ **@TK2MSFTNGP11 .phx.gbl>
| > | Subject: Re: Threading
| > | Date: Mon, 19 Dec 2005 09:43:27 -0000
| > | Lines: 77
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <OQ************ *@TK2MSFTNGP12. phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: ip-217-204-53-234.easynet.co. uk 217.204.53.234
| > | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
| > | Xref: TK2MSFTNGXA02.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:3656 58
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > |
| > | I DO need an STA thread, I'm creating an invisible window that hosts
| > mshtml
| > | and axwebrowser. I'm dynamically creating a bitmap using html. I need
| > some
| > | consistancy across platforms, I have this code working fine. But I
have
| > to
| > | create a thread(STA) to host it.
| > |
| > | In my testing i've noticed that the thread hangs arround in the
| > debugger.
| > | Even stripping my component out and creating the do almost nothing
| > thread
| > | example that i posted leaves this 'orphaned' thread. Regardless of the
| > | apartment state.
| > |
| > | I can't use the threadpool as the those threads are always MTA.
| > |
| > |
| > | "Alvin Bruney - ASP.NET MVP" <www.lulu.com/owc> wrote in message
| > | news:ez******** ******@TK2MSFTN GP11.phx.gbl...
| > | >I see no reason for STA thread based on the example you provided.
Care
| > to
| > | > elaborate? STA threads are for COM based process by the way.
| > | >
| > | > sorry, scratch that. I realized you were simply using incorrect
| > | > terminology.
| > | >
| > | > --
| > | > Regards,
| > | > Alvin Bruney [MVP ASP.NET]
| > | >
| > | > [Shameless Author plug]
| > | > The Microsoft Office Web Components Black Book with .NET
| > | > Now Available @ www.lulu.com/owc
| > | > Forth-coming VSTO.NET - Wrox/Wiley 2006
| > | > -------------------------------------------------------
| > | >
| > | >
| > | >
| > | > "AdrianJMar tin" <Ad***********@ newsgroups.nosp am> wrote in message
| > | > news:OI******** *****@tk2msftng p13.phx.gbl...
| > | >> Hi all,
| > | >>
| > | >> I have a need for a STA thread from asp.net. I can create the
thread
| > and
| > | > it
| > | >> runs fine. But when it is finished, the thread still 'hangs'
arround.
| > | >> Visible only to the debugger.....
| > | >> I get the "The thread has exited with code 0 (0x12fc)." in the
| > debugger
| > | >> each time the thread seemly end, but its still there in the thread
| > | >> window.
| > | >> GC.Collect() does not get rid of them either, something must be
| > holding a
| > | >> reference to the threads........ .
| > | >>
| > | >>
| > | >> a trivial example that demonstrates this
| > | >>
| > | >> public void Work()
| > | >> {
| > | >> Thread.Sleep( 5000 ) ;
| > | >> System.Diagnost ics.Debug.Write Line("Done!");
| > | >> }
| > | >>
| > | >> private void Button1_Click(o bject sender, System.EventArg s e)
| > | >> {
| > | >> ThreadStart ts = new ThreadStart( Work ) ;
| > | >> Thread t = new Thread( ts );
| > | >> t.Name = "test";
| > | >> t.Start();
| > | >> t.Join();
| > | >> Debug.WriteLine ( Process.GetCurr entProcess().Th reads.Count );
| > | >> t = null ;
| > | >> GC.Collect();
| > | >> }
| > | >>
| > | >>
| > | >> Is there anyway to clean up the Thread?
| > | >>
| > | >>
| > | >>
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|

Dec 21 '05 #8
Thank you Steven you have been very helpfull!

I modded your code to generate lots of threads per click, initialy they seem
to hang arround in the debugger. but i added some more code to remove
stopped threads from the arraylist( i assume they were still reachable
because of the reference in the arraylist). And now they are gone! GOOD.

I went back to my simpler code and noticed that if i detach and reattach the
debugger to aspnet_wp.exe then the thread window get updated correctly, so
i've been lead a bit of a dance by the vs2003 debugger!

Ta
Adrian


"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:dd******** ******@TK2MSFTN GXA02.phx.gbl.. .
Hi Adrian,

Thanks for your quick response.
For the Process.GetCurr entProcess().Th reads, it's a collection that
represents all the OS threads in the current running process(retriev e from
server's performance counter), we can see that the Thread's class is
"ProcessThr ead" rather than the System.Threadin g.Thread.....

Also, based on my local test, when creating a new thread that in STA
apartment model, it'll end successfully (the OS thread will also be
destoryed....). And for the .net's managed Thread class, it's threadState
will be set to "Stoped" when it has finished the work, we no longer need
to
worry about the sequential work since the CLR will take care of it.....

Here is a test page I used to print the process threads and the managed
threads (I manually created)'s status......

I contains three buttons , one used to printout OS threads, one used to
create new STA threads, and the third print out my managed threads:

=============== ==============
public class ThreadTest : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Butt on btnPrintThreads ;
protected System.Web.UI.W ebControls.Butt on btnStartThreads ;
protected System.Web.UI.W ebControls.Butt on btnPrintManaged Threads;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.btnPrintTh reads.Click += new
System.EventHan dler(this.btnPr intThreads_Clic k);
this.btnStartTh reads.Click += new
System.EventHan dler(this.btnSt artThreads_Clic k);
this.btnPrintMa nagedThreads.Cl ick += new
System.EventHan dler(this.btnPr intManagedThrea ds_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void btnStartThreads _Click(object sender, System.EventArg s e)
{
Thread td = new Thread(new ThreadStart(Wor k));

if(Application["threads"] == null)
{
Application["threads"] = new ArrayList();
}

ArrayList list = Application["threads"] as ArrayList;

list.Add(td);

td.ApartmentSta te = ApartmentState. STA;
td.Start();

}

private void btnPrintThreads _Click(object sender, System.EventArg s e)
{
Response.Write( "<br>========== ========");
Response.Write( "<br>OS threads: " +
Process.GetCurr entProcess().Th reads.Count);

foreach(Process Thread pt in Process.GetCurr entProcess().Th reads)
{
Response.Write( "<br>Id: " + pt.Id + " Status: " + pt.ThreadState) ;
}
}

private void btnPrintManaged Threads_Click(o bject sender, System.EventArg s
e)
{
if(Application["threads"] == null)
{
Application["threads"] = new ArrayList();
}

ArrayList list = Application["threads"] as ArrayList;

Response.Write( "<br>%%%%%%%%%% %%%%%%%%%%%%%%% %%%%%%");
Response.Write( "<br>Worker Threads: " + list.Count);

foreach(object obj in list)
{
Thread td = obj as Thread;
if(td != null)
{
Response.Write( "<br>Id: " + td.Name + " status: " + td.ThreadState) ;
}
}
}
public static void Work()
{
Thread.Sleep( 10000 ) ;
System.Diagnost ics.Debug.Write Line("Done!");
}
}
=============== =============

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "AdrianJMar tin" <Ad***********@ newsgroups.nosp am>
| References: <OI************ *@tk2msftngp13. phx.gbl>
<ez************ **@TK2MSFTNGP11 .phx.gbl>
<OQ************ *@TK2MSFTNGP12. phx.gbl>
<jk************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: Re: Threading
| Date: Tue, 20 Dec 2005 09:49:04 -0000
| Lines: 153
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <eG************ **@TK2MSFTNGP14 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ip-217-204-53-234.easynet.co. uk 217.204.53.234
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP14.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3659 06
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Hi Steven,
|
| Why would it be an OS thread I see? VS debugging is set to Managed only,
and
| I've name the thread. if you run the code below, press the button a few
| times, snap on a debugger break point inside Button1_Click(. ..) and see
that
| thread window is full of orphaned threads.( you may have Comment out the
| t.Join )
|
|
| Adrian
|
|
|
|
|
|
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:jk******** ******@TK2MSFTN GXA02.phx.gbl.. .
| > Hi Adrian,
| >
| > If the hang or unreleased thread you watched is the underlying
operating
| > system thread, then that should be reasonable since regardless of the
| > thread operation (start, end,.....), the CLR's unmanaged code has
| > structure
| > to hold reference to operating system thread. And so there is no
definite
| > mapping between the underlying operating system thread to the managed
CLR
| > thread instance..... Sometimes, our CLR t hread's work has finished,
the
| > underlying CLR structure may still hold the OS thread. Or other times
| > event
| > the OS thread has destroyed, the CLR's thread reference still refer to
a
| > managed thread object (for keepting some thread information.... )...
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | From: "AdrianJMar tin" <Ad***********@ newsgroups.nosp am>
| > | References: <OI************ *@tk2msftngp13. phx.gbl>
| > <ez************ **@TK2MSFTNGP11 .phx.gbl>
| > | Subject: Re: Threading
| > | Date: Mon, 19 Dec 2005 09:43:27 -0000
| > | Lines: 77
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <OQ************ *@TK2MSFTNGP12. phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: ip-217-204-53-234.easynet.co. uk 217.204.53.234
| > | Path:
TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
| > | Xref: TK2MSFTNGXA02.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:3656 58
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > |
| > | I DO need an STA thread, I'm creating an invisible window that hosts
| > mshtml
| > | and axwebrowser. I'm dynamically creating a bitmap using html. I
need
| > some
| > | consistancy across platforms, I have this code working fine. But I
have
| > to
| > | create a thread(STA) to host it.
| > |
| > | In my testing i've noticed that the thread hangs arround in the
| > debugger.
| > | Even stripping my component out and creating the do almost nothing
| > thread
| > | example that i posted leaves this 'orphaned' thread. Regardless of
the
| > | apartment state.
| > |
| > | I can't use the threadpool as the those threads are always MTA.
| > |
| > |
| > | "Alvin Bruney - ASP.NET MVP" <www.lulu.com/owc> wrote in message
| > | news:ez******** ******@TK2MSFTN GP11.phx.gbl...
| > | >I see no reason for STA thread based on the example you provided.
Care
| > to
| > | > elaborate? STA threads are for COM based process by the way.
| > | >
| > | > sorry, scratch that. I realized you were simply using incorrect
| > | > terminology.
| > | >
| > | > --
| > | > Regards,
| > | > Alvin Bruney [MVP ASP.NET]
| > | >
| > | > [Shameless Author plug]
| > | > The Microsoft Office Web Components Black Book with .NET
| > | > Now Available @ www.lulu.com/owc
| > | > Forth-coming VSTO.NET - Wrox/Wiley 2006
| > | > -------------------------------------------------------
| > | >
| > | >
| > | >
| > | > "AdrianJMar tin" <Ad***********@ newsgroups.nosp am> wrote in message
| > | > news:OI******** *****@tk2msftng p13.phx.gbl...
| > | >> Hi all,
| > | >>
| > | >> I have a need for a STA thread from asp.net. I can create the
thread
| > and
| > | > it
| > | >> runs fine. But when it is finished, the thread still 'hangs'
arround.
| > | >> Visible only to the debugger.....
| > | >> I get the "The thread has exited with code 0 (0x12fc)." in the
| > debugger
| > | >> each time the thread seemly end, but its still there in the
thread
| > | >> window.
| > | >> GC.Collect() does not get rid of them either, something must be
| > holding a
| > | >> reference to the threads........ .
| > | >>
| > | >>
| > | >> a trivial example that demonstrates this
| > | >>
| > | >> public void Work()
| > | >> {
| > | >> Thread.Sleep( 5000 ) ;
| > | >> System.Diagnost ics.Debug.Write Line("Done!");
| > | >> }
| > | >>
| > | >> private void Button1_Click(o bject sender, System.EventArg s e)
| > | >> {
| > | >> ThreadStart ts = new ThreadStart( Work ) ;
| > | >> Thread t = new Thread( ts );
| > | >> t.Name = "test";
| > | >> t.Start();
| > | >> t.Join();
| > | >> Debug.WriteLine ( Process.GetCurr entProcess().Th reads.Count );
| > | >> t = null ;
| > | >> GC.Collect();
| > | >> }
| > | >>
| > | >>
| > | >> Is there anyway to clean up the Thread?
| > | >>
| > | >>
| > | >>
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|

Dec 21 '05 #9
Thanks for your followup Adrian,

Yes, that's also why I'd prefered test through the page out of debugger (or
in debuggin mode...) :-)...

Have a good day!

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "AdrianJMar tin" <Ad***********@ newsgroups.nosp am>
| References: <OI************ *@tk2msftngp13. phx.gbl>
<ez************ **@TK2MSFTNGP11 .phx.gbl>
<OQ************ *@TK2MSFTNGP12. phx.gbl>
<jk************ **@TK2MSFTNGXA0 2.phx.gbl>
<eG************ **@TK2MSFTNGP14 .phx.gbl>
<dd************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: Re: Threading
| Date: Wed, 21 Dec 2005 09:59:55 -0000
| Lines: 352
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <eL************ **@TK2MSFTNGP14 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ip-217-204-53-234.easynet.co. uk 217.204.53.234
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP14.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3661 88
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Thank you Steven you have been very helpfull!
|
| I modded your code to generate lots of threads per click, initialy they
seem
| to hang arround in the debugger. but i added some more code to remove
| stopped threads from the arraylist( i assume they were still reachable
| because of the reference in the arraylist). And now they are gone! GOOD.
|
| I went back to my simpler code and noticed that if i detach and reattach
the
| debugger to aspnet_wp.exe then the thread window get updated correctly,
so
| i've been lead a bit of a dance by the vs2003 debugger!
|
|
|
| Ta
| Adrian
|
|
|
|
|
|
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:dd******** ******@TK2MSFTN GXA02.phx.gbl.. .
| > Hi Adrian,
| >
| > Thanks for your quick response.
| > For the Process.GetCurr entProcess().Th reads, it's a collection that
| > represents all the OS threads in the current running process(retriev e
from
| > server's performance counter), we can see that the Thread's class is
| > "ProcessThr ead" rather than the System.Threadin g.Thread.....
| >
| > Also, based on my local test, when creating a new thread that in STA
| > apartment model, it'll end successfully (the OS thread will also be
| > destoryed....). And for the .net's managed Thread class, it's
threadState
| > will be set to "Stoped" when it has finished the work, we no longer
need
| > to
| > worry about the sequential work since the CLR will take care of it.....
| >
| > Here is a test page I used to print the process threads and the managed
| > threads (I manually created)'s status......
| >
| > I contains three buttons , one used to printout OS threads, one used to
| > create new STA threads, and the third print out my managed threads:
| >
| > =============== ==============
| > public class ThreadTest : System.Web.UI.P age
| > {
| > protected System.Web.UI.W ebControls.Butt on btnPrintThreads ;
| > protected System.Web.UI.W ebControls.Butt on btnStartThreads ;
| > protected System.Web.UI.W ebControls.Butt on btnPrintManaged Threads;
| >
| > private void Page_Load(objec t sender, System.EventArg s e)
| > {
| > // Put user code to initialize the page here
| > }
| >
| > #region Web Form Designer generated code
| > override protected void OnInit(EventArg s e)
| > {
| > //
| > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
| > //
| > InitializeCompo nent();
| > base.OnInit(e);
| > }
| >
| > /// <summary>
| > /// Required method for Designer support - do not modify
| > /// the contents of this method with the code editor.
| > /// </summary>
| > private void InitializeCompo nent()
| > {
| > this.btnPrintTh reads.Click += new
| > System.EventHan dler(this.btnPr intThreads_Clic k);
| > this.btnStartTh reads.Click += new
| > System.EventHan dler(this.btnSt artThreads_Clic k);
| > this.btnPrintMa nagedThreads.Cl ick += new
| > System.EventHan dler(this.btnPr intManagedThrea ds_Click);
| > this.Load += new System.EventHan dler(this.Page_ Load);
| >
| > }
| > #endregion
| >
| > private void btnStartThreads _Click(object sender, System.EventArg s e)
| > {
| > Thread td = new Thread(new ThreadStart(Wor k));
| >
| >
| >
| > if(Application["threads"] == null)
| > {
| > Application["threads"] = new ArrayList();
| > }
| >
| > ArrayList list = Application["threads"] as ArrayList;
| >
| > list.Add(td);
| >
| > td.ApartmentSta te = ApartmentState. STA;
| > td.Start();
| >
| > }
| >
| > private void btnPrintThreads _Click(object sender, System.EventArg s e)
| > {
| > Response.Write( "<br>========== ========");
| > Response.Write( "<br>OS threads: " +
| > Process.GetCurr entProcess().Th reads.Count);
| >
| > foreach(Process Thread pt in Process.GetCurr entProcess().Th reads)
| > {
| > Response.Write( "<br>Id: " + pt.Id + " Status: " + pt.ThreadState) ;
| > }
| > }
| >
| > private void btnPrintManaged Threads_Click(o bject sender,
System.EventArg s
| > e)
| > {
| > if(Application["threads"] == null)
| > {
| > Application["threads"] = new ArrayList();
| > }
| >
| > ArrayList list = Application["threads"] as ArrayList;
| >
| > Response.Write( "<br>%%%%%%%%%% %%%%%%%%%%%%%%% %%%%%%");
| > Response.Write( "<br>Worker Threads: " + list.Count);
| >
| > foreach(object obj in list)
| > {
| > Thread td = obj as Thread;
| > if(td != null)
| > {
| > Response.Write( "<br>Id: " + td.Name + " status: " + td.ThreadState) ;
| > }
| > }
| >
| >
| > }
| >
| >
| > public static void Work()
| > {
| > Thread.Sleep( 10000 ) ;
| > System.Diagnost ics.Debug.Write Line("Done!");
| > }
| > }
| > =============== =============
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| > --------------------
| > | From: "AdrianJMar tin" <Ad***********@ newsgroups.nosp am>
| > | References: <OI************ *@tk2msftngp13. phx.gbl>
| > <ez************ **@TK2MSFTNGP11 .phx.gbl>
| > <OQ************ *@TK2MSFTNGP12. phx.gbl>
| > <jk************ **@TK2MSFTNGXA0 2.phx.gbl>
| > | Subject: Re: Threading
| > | Date: Tue, 20 Dec 2005 09:49:04 -0000
| > | Lines: 153
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | X-RFC2646: Format=Flowed; Original
| > | Message-ID: <eG************ **@TK2MSFTNGP14 .phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: ip-217-204-53-234.easynet.co. uk 217.204.53.234
| > | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP14.phx. gbl
| > | Xref: TK2MSFTNGXA02.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:3659 06
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > |
| > | Hi Steven,
| > |
| > | Why would it be an OS thread I see? VS debugging is set to Managed
only,
| > and
| > | I've name the thread. if you run the code below, press the button a
few
| > | times, snap on a debugger break point inside Button1_Click(. ..) and
see
| > that
| > | thread window is full of orphaned threads.( you may have Comment out
the
| > | t.Join )
| > |
| > |
| > | Adrian
| > |
| > |
| > |
| > |
| > |
| > |
| > | "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| > | news:jk******** ******@TK2MSFTN GXA02.phx.gbl.. .
| > | > Hi Adrian,
| > | >
| > | > If the hang or unreleased thread you watched is the underlying
| > operating
| > | > system thread, then that should be reasonable since regardless of
the
| > | > thread operation (start, end,.....), the CLR's unmanaged code has
| > | > structure
| > | > to hold reference to operating system thread. And so there is no
| > definite
| > | > mapping between the underlying operating system thread to the
managed
| > CLR
| > | > thread instance..... Sometimes, our CLR t hread's work has
finished,
| > the
| > | > underlying CLR structure may still hold the OS thread. Or other
times
| > | > event
| > | > the OS thread has destroyed, the CLR's thread reference still refer
to
| > a
| > | > managed thread object (for keepting some thread information.... )...
| > | >
| > | > Thanks,
| > | >
| > | > Steven Cheng
| > | > Microsoft Online Support
| > | >
| > | > Get Secure! www.microsoft.com/security
| > | > (This posting is provided "AS IS", with no warranties, and confers
no
| > | > rights.)
| > | >
| > | >
| > | >
| > | > --------------------
| > | > | From: "AdrianJMar tin" <Ad***********@ newsgroups.nosp am>
| > | > | References: <OI************ *@tk2msftngp13. phx.gbl>
| > | > <ez************ **@TK2MSFTNGP11 .phx.gbl>
| > | > | Subject: Re: Threading
| > | > | Date: Mon, 19 Dec 2005 09:43:27 -0000
| > | > | Lines: 77
| > | > | X-Priority: 3
| > | > | X-MSMail-Priority: Normal
| > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| > | > | X-RFC2646: Format=Flowed; Original
| > | > | Message-ID: <OQ************ *@TK2MSFTNGP12. phx.gbl>
| > | > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | > | NNTP-Posting-Host: ip-217-204-53-234.easynet.co. uk 217.204.53.234
| > | > | Path:
| > TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
| > | > | Xref: TK2MSFTNGXA02.p hx.gbl
| > | > microsoft.publi c.dotnet.framew ork.aspnet:3656 58
| > | > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > | > |
| > | > | I DO need an STA thread, I'm creating an invisible window that
hosts
| > | > mshtml
| > | > | and axwebrowser. I'm dynamically creating a bitmap using html. I
| > need
| > | > some
| > | > | consistancy across platforms, I have this code working fine. But I
| > have
| > | > to
| > | > | create a thread(STA) to host it.
| > | > |
| > | > | In my testing i've noticed that the thread hangs arround in the
| > | > debugger.
| > | > | Even stripping my component out and creating the do almost nothing
| > | > thread
| > | > | example that i posted leaves this 'orphaned' thread. Regardless
of
| > the
| > | > | apartment state.
| > | > |
| > | > | I can't use the threadpool as the those threads are always MTA.
| > | > |
| > | > |
| > | > | "Alvin Bruney - ASP.NET MVP" <www.lulu.com/owc> wrote in message
| > | > | news:ez******** ******@TK2MSFTN GP11.phx.gbl...
| > | > | >I see no reason for STA thread based on the example you provided.
| > Care
| > | > to
| > | > | > elaborate? STA threads are for COM based process by the way.
| > | > | >
| > | > | > sorry, scratch that. I realized you were simply using incorrect
| > | > | > terminology.
| > | > | >
| > | > | > --
| > | > | > Regards,
| > | > | > Alvin Bruney [MVP ASP.NET]
| > | > | >
| > | > | > [Shameless Author plug]
| > | > | > The Microsoft Office Web Components Black Book with .NET
| > | > | > Now Available @ www.lulu.com/owc
| > | > | > Forth-coming VSTO.NET - Wrox/Wiley 2006
| > | > | > -------------------------------------------------------
| > | > | >
| > | > | >
| > | > | >
| > | > | > "AdrianJMar tin" <Ad***********@ newsgroups.nosp am> wrote in
message
| > | > | > news:OI******** *****@tk2msftng p13.phx.gbl...
| > | > | >> Hi all,
| > | > | >>
| > | > | >> I have a need for a STA thread from asp.net. I can create the
| > thread
| > | > and
| > | > | > it
| > | > | >> runs fine. But when it is finished, the thread still 'hangs'
| > arround.
| > | > | >> Visible only to the debugger.....
| > | > | >> I get the "The thread has exited with code 0 (0x12fc)." in the
| > | > debugger
| > | > | >> each time the thread seemly end, but its still there in the
| > thread
| > | > | >> window.
| > | > | >> GC.Collect() does not get rid of them either, something must be
| > | > holding a
| > | > | >> reference to the threads........ .
| > | > | >>
| > | > | >>
| > | > | >> a trivial example that demonstrates this
| > | > | >>
| > | > | >> public void Work()
| > | > | >> {
| > | > | >> Thread.Sleep( 5000 ) ;
| > | > | >> System.Diagnost ics.Debug.Write Line("Done!");
| > | > | >> }
| > | > | >>
| > | > | >> private void Button1_Click(o bject sender, System.EventArg s e)
| > | > | >> {
| > | > | >> ThreadStart ts = new ThreadStart( Work ) ;
| > | > | >> Thread t = new Thread( ts );
| > | > | >> t.Name = "test";
| > | > | >> t.Start();
| > | > | >> t.Join();
| > | > | >> Debug.WriteLine ( Process.GetCurr entProcess().Th reads.Count );
| > | > | >> t = null ;
| > | > | >> GC.Collect();
| > | > | >> }
| > | > | >>
| > | > | >>
| > | > | >> Is there anyway to clean up the Thread?
| > | > | >>
| > | > | >>
| > | > | >>
| > | > | >
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Dec 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
6729
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the language's 30+ year evolution. What to you think python largest compromises are? The three that come to my mind are significant whitespace, dynamic typing, and that it is interpreted - not compiled. These three put python under fire and cause...
2
2978
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def get_all_files(path): """return all files of folder path, scan with subfolders
77
5274
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go through the whole thing!) to check for accuracy, effectiveness of examples, etc. Feel free to mail...
6
555
by: CK | last post by:
I have the following code in a windows service, when I start the windows service process1 and process2 work fine , but final process (3) doesnt get called. i stop and restart the windows service and the final process(3) gets called. what am I doing wrong with the threading? by the way Directory.GetFiles(IncomingXMLPath1).Length is some global outcome from process 1. Thanks 1)
2
2244
by: Vjay77 | last post by:
In this code: Private Sub downloadBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Not (Me.downloadUrlTextBox.Text = "") Then Me.outputGroupBox.Enabled = True Me.bytesDownloadedTextBox.Text = "" Me.totalBytesTextBox.Text = ""
11
5019
by: Paul Sijben | last post by:
I am stumped by the following problem. I have a large multi-threaded server accepting communications on one UDP port (chosen for its supposed speed). I have been profiling the code and found that the UDP communication is my biggest drain on performance! Communication where the client and the server are on the same machine still takes 300ms or sometimes much more per packet on an Athlon64 3000+ running Linux (Fedora Core 5 x64). I must...
17
6418
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from python.org) have this problem. The operating system is MS Windows XP Professional.
0
1591
by: kingcrowbar.list | last post by:
Hello Everyone I have been playing a little with pyGTK and threading to come up with simple alert dialog which plays a sound in the background. The need for threading came when in the first version i made, the gui would freeze after clicking the close button until pygame finished playing the sound. In Windows it was acceptable because it could be ignored easily, but in
7
2374
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has finished. I am trying to follow this example : http://www.codeproject.com/cs/miscctrl/progressdialog.asp But although the messages still get moved, the progress window never does anything. Here is my code in full, if anybody who knows...
126
6698
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard: http://www.cse.wustl.edu/~schmidt/ACE.html the same way that the STL (and subsequently BOOST) have been subsumed? Since it already runs on zillions of platforms, they have obviously worked most of the kinks out of the generalized threading and processes idea (along with many...
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.