About threading

J

Jordi Rico

Hi,
I'm developing a new app.
I'm using threads, I have used it before, but I'm not sure of some
issues when threading as I'm not an expert with this.
I'll go with a direct example of what I'm doing, I know that is not
very correct, but it's the only way I know, so if someone knows how to
do it better, please tell me.

When I click some button i create a new thread:

private sub button1_click(.....)
t=new thread(addressof listenevents) ' t is a global variable
end sub

public sub listenevents
while true
' here is code of a socket listening to a port and processing all
received data
end while
end sub

When I want to stop the socket listener, in other button I have this:

private sub button2_click(.....)
t.suspend()
end sub


The problem is that I know that this method is deprecated, so I suppose
it's not the correct way of doing this code, can anybody help??
Thanks
 
J

Jared Parsons [MSFT]

Hello Jordi,
When I want to stop the socket listener, in other button I have this:

private sub button2_click(.....)
t.suspend()
end sub
The problem is that I know that this method is deprecated, so I
suppose
it's not the correct way of doing this code, can anybody help??

What kind of behavior are you looking for here? Do you want to essentially
end the thread permanently? If so then use the .Abort() sub to end the thread.
 
J

Jordi Rico

The problem is that inside the infinite loop of the thread, as the
socket stops the execution until it receives some data from the port,
if I make a thread.abort() I receive an exception from the socket, 'cos
it stops in a wrong way...
I've found that if I make a disconnect from the socket, I can execute
the next statement inside the loop and find if the socket has
disconnected, so I can know if I have to end the loop.
I've passed through this immediate problem this way, but I'll have to
find a good tutorial about threads to learn more about them...
Thanks

Jared ha escrito:
Hello Jordi,
When I want to stop the socket listener, in other button I have this:

private sub button2_click(.....)
t.suspend()
end sub
The problem is that I know that this method is deprecated, so I
suppose
it's not the correct way of doing this code, can anybody help??

What kind of behavior are you looking for here? Do you want to essentially
end the thread permanently? If so then use the .Abort() sub to end the thread.


--
Jared Parsons [MSFT]
(e-mail address removed)
All opinions are my own. All content is provided "AS IS" with no warranties,
and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top