RE: How do you kill a completly locked up thread?

Tech-Archive recommends: Fix windows errors by optimizing your registry



Here is a code snippit from an asynch callback that I am sure is one of the
causes of my thread being locked up when the SharpSSH shell object dies.

ReadDataCallback = new AsyncCallback(OnReadData);
shell.IO.BeginRead(RecvBuff, 0, RecvBuff.Length,
ReadDataCallback, null);

while (true == shell.ShellOpened)
{
// See if we have data to send
lock (SendBuffer)
{
if (0 != SendBuffer.Length)
{
shell.Write(SendBuffer);
SendBuffer = string.Empty;
}
}

Thread.Sleep(50);
}

I am not sure how to set the ReadDataCallback up so that it can recover from
a hard lockup from the shell object. The method on the egghead cafe page
doesn't seem to fit this very well.



"Peter Bromberg [C# MVP]" wrote:

Here is an article with an approach that allows to make any method call
"time-outable":
http://www.eggheadcafe.com/tutorials/aspnet/847c94bf-4b8d-4a66-9ae5-5b61f049019f/basics-make-any-method-c.aspx
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com


"TheSilverHammer" wrote:

Because C# has no native SSH class, I am using SharpSSH. Sometimes, for
reasons I do not know, a Connect call will totally lock up the thread and
never return. I am sure it has something to do with weirdness going on with
the server I am talking to. Anyhow, this locked up state happens once in a
while (maybe once per day) and I can't figure out how to deal with the locked
up thread.

If I issue a Thread.Abort() the exception never gets thrown in the thread
because it is locked up. This seems to be the only C# method I know of to
kill a thread. Is there some other way to kill off a thread?

A way you can simulate this yourself, is create any thread that connects to
a server where the connection takes some time, like 10 to 20 seconds. When
the thread is doing this connect (it will happen with even a simple TCP/IP
socket connect) issue a Thread.Abort() from another thread (the one that made
the Thread Object) and you will see that the ThreadAbortException will NOT be
thrown until the Connect call returns.

Another way you can do this is after the connect call is finished and you
start to talk to a server, if you are on a recive data call and the server
stops sending data but never closes the connection, it will block forever.
You will once again not be able to get Thread.Abort() to kill the locked up
thread.

Is there anyone, especially a MSVP who can answer this?
.



Relevant Pages

  • Re: named startup problems upgrading from 7.1p4 to 7.1p5 or 7.1p6
    ... Sorry for starting a new thread with this - my ISP's mail server seems to rejecting all mail recipients when I ... file being created) or by a kill command other than kill -9. ... local devdir rs _me ... Running any rndc command causes rndc to load ...
    (freebsd-questions)
  • Re: background/SIGTERM
    ... > Can I start the server in background-mode, ... > 2) To terminate the server I curently use WRKACTJOB and then terminate ... That's because you a never ending command in your interactive session; ... you kill the job, you kill the session. ...
    (comp.sys.ibm.as400.misc)
  • Re: First Server Kill - and no loot.
    ... first kill of this mob on our server. ... Right when the last add died, we all got disconnected from the server. ... The GMs said there "must have been a mini rollback" and they cannot ... One final run, with all guild GMs playing together, the instance clones. ...
    (alt.games.warcraft)
  • Re: Problems with Xorg after portupgrade
    ... kill the X server via CTRL+C. ... Then you should be able to Ctrl+Alt+BkSpace to kill X. ... to indicate that leaving it commented out activates the sequence. ... Hence disabling DontZap allows X-Server ...
    (freebsd-questions)
  • Re: Kill TCP session
    ... kill is used to kill process. ... How it's possible to kill a tcp session btw client and solaris server ... i have some tcp connexion to the application running on my solaris ...
    (comp.unix.solaris)