We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Good terminating threads in compact dontnet framework 2.0 in vb.net

Medium Priority
698 Views
Last Modified: 2013-12-27
I am using a google web service in my application for PDA  , and this web service executed by a separated thread , but the response of the web service not always success , that make the application freezed with error message .
How I emulate Thread.isAlive method and avoid running many threads and to be sure the thread is 100% terminated before calling the thread again ?
Please in VB.net example
My application run for 3 Hours then freezed
PDA is a windows mobile 6.5 pro OS  , I am using VS2005  
Comment
Watch Question

hjgodeTier 3 Senior Technical Support Engineer
CERTIFIED EXPERT

Commented:
Here is a pseudo code snippet:

sub thread
  try
    while(bRunThread)
      'Do work
    wend
  catch(ThreadAbortException)
  end try
  bThreadIsStopped=TRUE
end sub

in main code you can set bRunThread to False but this will terminate thread not directly. Better use Thread.Abort to produce a thread abort exception and then the try/catch will end your thread. Then in main check if bThreadIsStopped.

I can only provide csharp sample: see http://www.hjgode.de/wp/2010/06/01/mobile-development-easy-to-use-background-thread-with-gui-update/

regards

Josef

Author

Commented:
  I think it the same problem i have
sub thread
  try
    while(bRunThread)
      'Do work
 >>>> here were the web service kill wend loop that preventing thread to be terminated <<< 
    wend
  catch(ThreadAbortException)
  end try
  bThreadIsStopped=TRUE
end sub
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Try calling the thread.Abort function from the main code.
hjgodeTier 3 Senior Technical Support Engineer
CERTIFIED EXPERT

Commented:
Yes, that is the same I suggested.

a) you create the thread from main code
b) Thread.Abort will also work for long blocking call inside while loop and the ThreadAbortEception is fired
c) the var setting at the end of the thread will allow you to check if the thread is still running

regards

Josef

Author

Commented:

I made a simple code for test but I found a problem  
bThreadIsStopped=TRUE statement reached in debugging mode normally by setting
bRunThread = false in the main code that is ok but using Thread.Abort  the ThreadAbortException triggered and not reached the bThreadIsStopped=TRUE statement which mean the thread still running or should i modify the code as
try
while(bRunThread)
'Do work

    wend
    catch(ThreadAbortException)
    bThreadIsStopped=TRUE <<<<<<<   is this right  ??? to indicate the termination
   end try
    bThreadIsStopped=TRUE  <<<<<<   not reached in case ThreadAbortException
 end sub

Author

Commented:

In normal case if the thread sub method returned without error  is this mean that thread really terminated ?
as the example when we set bThreadIsStopped=TRUE and exit while loop normally
Tier 3 Senior Technical Support Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.