1

i want to write an application peer to peer program, this is my piece of code.

    public void ArrestaServer()
    {
        if (ThreadAscolta.ThreadState==ThreadState.Running)
            ThreadAscolta.Suspend();
    }

        public void AvviaServer()
        {
            if (ThreadAscolta == null)
            {
                ThreadAscolta = new Thread(ServerRicevi);
                ThreadAscolta.Start();
                while (!(ThreadAscolta.IsAlive)) ;
            }
            else if (ThreadAscolta.ThreadState==ThreadState.SuspendRequested)
                ThreadAscolta.Resume();
        }

How can i remove these alerts?

System.Threading.Thread.Resume(): "Thread.Resume has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources."

System.Threading.Thread.Suspend(): "Thread.Suspend has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources."

leppie
  • 115,091
  • 17
  • 196
  • 297
  • 6
    Multi-threading isn't something you can do on a guessing basis. Using `Thread.Suspend` and `Thread.Abort` is a bad idea, and so is doing things like `while (!(ThreadAscolta.IsAlive));`. Try this for a starter - http://www.albahari.com/threading/ And I assume you're writing a network server - that shouldn't really use threads anyway. Just have a look at the asynchronous APIs for whatever network classes you're using. – Luaan May 28 '15 at 06:52
  • 1
    *How can i remove these alerts?* it is right there in the warning. " Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources" – Sriram Sakthivel May 28 '15 at 07:06

0 Answers0