About threading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jordi Rico

    #1

    About threading

    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(addresso f 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

  • Jared Parsons [MSFT]

    #2
    Re: About threading

    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]
    jaredpar@online .microsoft.com
    All opinions are my own. All content is provided "AS IS" with no warranties,
    and confers no rights.


    Comment

    • Jordi Rico

      #3
      Re: About threading

      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]
      jaredpar@online .microsoft.com
      All opinions are my own. All content is provided "AS IS" with no warranties,
      and confers no rights.

      Comment

      Working...