[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

09/02/2003 at 01:41AM PDT, ID: 20726281
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

unconditional thread abort

Asked by Azmodan in .NET

Tags: threadabortexception

I want to abort (kill) a thread no matter what. In the documentation it says that if the thread is in an unmanaged code portion when the ThreadAbortException is thrown, the system will rethrow it when managed code is executed. But what if the thread is stuck in an unmanaged method? how can I kill the thread?

(as a side note, Socket.Receive() appears to be unmanaged!!! )

here is a small sample that uses 2 threads that get hung in a socket.receive and cannot be aborted. (i wanted them to get hunged!). If the socket part is commented, it works!



using System;
using System.Threading;
using System.Net;
using System.Net.Sockets;

namespace ConsoleApplication2
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      ///

      class MyThread
      {
            public MyThread()
            {
            }

            public void run()
            {
                  int i=0;
                  int k=0;
                  Console.WriteLine("init thread " + this.GetHashCode());
                  while(true)
                  {
                        Console.WriteLine("thread " + this.GetHashCode() + " " + i++);
                        Thread.Sleep(1000);

                        //----begin socket part---
                        Socket sock = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);

                                                      //bogus address, nothigs come from here so that the Receive method will run forever!
                        IPAddress hostIPAddress1 = (Dns.Resolve("europe.battle.net")).AddressList[0];                        sock.Connect(new IPEndPoint(hostIPAddress1,80));
                        byte[] bytes = new byte[256];
                        k=sock.Receive(bytes);
                        Console.WriteLine("Received " + k + " bytes");
                        //---end socket part---
                  }
            }
      }

      class Class1
      {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main(string[] args)
            {
                  //
                  // TODO: Add code to start application here
                  //
                  Start();
            }

            public static void Start()
            {
                  MyThread myTh1 = new MyThread();
                  Thread th1 = new Thread(new ThreadStart(myTh1.run));
                  th1.Name="TH1";
                  th1.Start();
                  
                  MyThread myTh2 = new MyThread();
                  Thread th2 = new Thread(new ThreadStart(myTh2.run));
                  th2.Name="TH2";
                  th2.Start();

                  Thread.Sleep(5000);

                  th1.Abort();
                  Thread.Sleep(500);
                  Console.WriteLine("th1 aborted -> status: " + th1.ThreadState.ToString());

                  Thread.Sleep(6000);

                  th2.Abort();
                  Thread.Sleep(500);
                  Console.WriteLine("th2 aborted -> status: " + th2.ThreadState.ToString());

            }
      }
}
[+][-]09/02/03 07:22 AM, ID: 9267450

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/02/03 07:33 AM, ID: 9267533

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/02/03 08:43 AM, ID: 9268061

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/02/03 08:54 AM, ID: 9268153

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/02/03 04:43 PM, ID: 9270931

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/02/03 11:27 PM, ID: 9272289

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/03/03 08:22 AM, ID: 9277821

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: .NET
Tags: threadabortexception
Sign Up Now!
Solution Provided By: SeanChapman
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20090824-EE-VQP-74