PC Review


Reply
Thread Tools Rate Thread

Aborting a Thread

 
 
=?Utf-8?B?RG9taW5payBIYW5lYmVyZw==?=
Guest
Posts: n/a
 
      18th Feb 2004
Hi
I'm writing an application in C# for PocketPC 2003. The application should use a thread to read data from a bluetooth connection. If the connection is no longer needed I want to stop and destroy the thread. As I understand the .NET CF does not support Thread.Abort(). How can threads be terminated in .NET CF

Thanks for your help
Kind regards

Dominik
 
Reply With Quote
 
 
 
 
Elisa
Guest
Posts: n/a
 
      18th Feb 2004
Hi Dominik,

There is indeed no functionality in .NET CF to abort a thread. So far
I've encountered two solutions to get around this:

1. use a flag to request the thread to stop running.
2. set the thread object to nil (Nothing in VB).

I prefer method 1. In pseudo-code it would look something like this:

class MyClass {

stopFlag = false
threadRunning = false

someMethod {
startThread(myThreadProc)
}

anotherMethod {
stopFlag = true
while threadRunning {
Sleep(250)
}
}

myThreadProc {
threadRunning = true
while not stopFlag {
doStuff()
}
threadRunning = false
}

}


Regards,

Elisa
 
Reply With Quote
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      18th Feb 2004
A third option is to set a system event in the primary thread and have the
worker periodically check for it. Same functionality as a flag, but not
global variable.

-Chris

"Elisa" <(E-Mail Removed)> wrote in message
news:m5HYb.5633$(E-Mail Removed)...
> Hi Dominik,
>
> There is indeed no functionality in .NET CF to abort a thread. So far
> I've encountered two solutions to get around this:
>
> 1. use a flag to request the thread to stop running.
> 2. set the thread object to nil (Nothing in VB).
>
> I prefer method 1. In pseudo-code it would look something like this:
>
> class MyClass {
>
> stopFlag = false
> threadRunning = false
>
> someMethod {
> startThread(myThreadProc)
> }
>
> anotherMethod {
> stopFlag = true
> while threadRunning {
> Sleep(250)
> }
> }
>
> myThreadProc {
> threadRunning = true
> while not stopFlag {
> doStuff()
> }
> threadRunning = false
> }
>
> }
>
>
> Regards,
>
> Elisa



 
Reply With Quote
 
Dick Grier
Guest
Posts: n/a
 
      18th Feb 2004
Hi,

>>

2. set the thread object to nil (Nothing in VB).
<<

The other reason to prefer method 1 (or Chris's suggestion), is because this
doesn't work reliably (in my experience).

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.


 
Reply With Quote
 
Geoff Schwab [MSFT]
Guest
Posts: n/a
 
      18th Feb 2004
There is a simple howto that implements the global method:

http://msdn.microsoft.com/library/en...tml/stopmt.asp

--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/p...Q/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
"Dominik Haneberg" <(E-Mail Removed)> wrote in message
news:93E7500E-378B-4422-91A7-(E-Mail Removed)...
> Hi,
> I'm writing an application in C# for PocketPC 2003. The application should

use a thread to read data from a bluetooth connection. If the connection is
no longer needed I want to stop and destroy the thread. As I understand the
..NET CF does not support Thread.Abort(). How can threads be terminated in
..NET CF?
>
> Thanks for your help.
> Kind regards.
>
> Dominik



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thread.Abort not really aborting thread. Mufasa Microsoft C# .NET 4 12th Jun 2007 05:40 PM
Aborting a thread while on sleep =?Utf-8?B?YmFyYnV0eg==?= Microsoft Dot NET Framework 6 31st Jan 2006 08:24 PM
Aborting a thread ? jmd.msdn Microsoft C# .NET 3 6th Jan 2006 07:15 PM
Thread .Aborting Xarky Microsoft C# .NET 2 8th Mar 2005 05:44 PM
aborting a thread in C# =?Utf-8?B?QWJoaW5hdiBQYXRoYWs=?= Microsoft C# .NET 1 24th Dec 2004 10:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:21 PM.