locked
What happens to a thread if I don't call the End… method? RRS feed

  • Question

  • I have a web service reference proxy class with generated asynchronous methods. I call a method using BeginMethodName. I can pass a callback function and then in the callback function call EndMethodName to get results or an exception. But what will happen to the parallel thread if I don't call EndMethodName? I've tried to monitor the app using debugger and it looks like those threads get killed any way. But that might be due to their master thread being killed. But what if master thread won't get killed? Will those parallel proxy threads be killed by some timeout? I don't need to know the result of the method call, and the method call is OneWay any way.
    Friday, June 7, 2013 1:46 PM

Answers

  • When a client/socket class is constructed default event handlers are gererated for all methods including the socket close event.  When the socket is closed all the resources will be disposed using the default evnet handlers that were created when the class was constructed.  If you code replaced the default event handlers these to will get disposed.  so there is no isues as long as the soket get closed by either end of the connections.  When an VS application gets closed all threads will get terminated and as part of the closing of the threads the sockets associated with the threads will also get closed.  The only time the sockets will not get closed if your application spawned another process that isn't connected by a thread.

    Sockets will automaticaly get closed if a timeout other than zero is the client/socket class provided keepalive option is not used when the channel remain idle for a period of time.


    jdweng

    Friday, June 7, 2013 4:12 PM

All replies

  • When a client/socket class is constructed default event handlers are gererated for all methods including the socket close event.  When the socket is closed all the resources will be disposed using the default evnet handlers that were created when the class was constructed.  If you code replaced the default event handlers these to will get disposed.  so there is no isues as long as the soket get closed by either end of the connections.  When an VS application gets closed all threads will get terminated and as part of the closing of the threads the sockets associated with the threads will also get closed.  The only time the sockets will not get closed if your application spawned another process that isn't connected by a thread.

    Sockets will automaticaly get closed if a timeout other than zero is the client/socket class provided keepalive option is not used when the channel remain idle for a period of time.


    jdweng

    Friday, June 7, 2013 4:12 PM
  • Thank you for your answer, but can you clarify the following?

    If I launched a request asynchronously using Begin... method, but didn't read the result or exception using End... method, then what will happen with the resources, the async thread that was used to call the web service and the channel in that case?

    Friday, June 7, 2013 4:37 PM
  • Your application owns the socket.  When you application ends the socket is disposed.  During the dispose of the socket, any events that are registered by the socket are removed so any  incoming message to the event are stopped.  Then the socket is closed and disposed.

    jdweng

    Friday, June 7, 2013 4:45 PM
  • What if my application doesn't stop? What goes on with the async thread and other resources before the timeout occur?
    Friday, June 7, 2013 5:31 PM
  • The process continue to run like any other background process on the PC.  The ASYC behaves just like any other process on the PC.


    jdweng

    Friday, June 7, 2013 9:48 PM