Home > Net >  Threads run after a period of time of using the program can't response, ask the reason, how to
Threads run after a period of time of using the program can't response, ask the reason, how to

Time:09-27

Code:
Private void btnStart_Click (object sender, EventArgs e)
{
Thread threadWork=new Thread (new ThreadStart (enclosing ReturnState));
ThreadWork. Start ();
ThreadWork. IsBackground=true;
}

Public void ReturnState ()
{
While (true)
{
Thread.sleep (1);
The if ()
.
}
}

CodePudding user response:

1. ThreadWork. Start ();
ThreadWork. IsBackground=true; Both a change of position
2. Click on the button to create a thread has no place to stop the thread thread more check internal thread whether there is leakage cause of memory or the thread interface controls where the internal thread to open more leads to interface card after death is not responding

CodePudding user response:

Thread used within the while (true) have effect?

CodePudding user response:

First look at the log, the specific reason is what
Sleep (1) to sleep (1000).

CodePudding user response:

General internal thread, to see whether the thread code

CodePudding user response:

I would rather use a timer based on thread back to use while (true), visual inspection is the logical problem in if statements

CodePudding user response:

In the visual IF lead to write code

CodePudding user response:

reference 1st floor OrdinaryCoder response:
1. The threadWork. Start ();
ThreadWork. IsBackground=true; Both a change of position
2. Click on the button to create a thread has no place to stop the thread thread more check internal thread whether there is leakage cause of memory or the thread interface controls where the internal thread to open more leads to interface card after death is also not response

CodePudding user response:

No need long-term monitoring, threads do not shut down, how to operate

CodePudding user response:

Threads in front of each execution method to an int variable assignment, and then print the value of this variable, observe stuck there
  •  Tags:  
  • C#
  • Related