Click here to Skip to main content
15,897,518 members
Home / Discussions / C#
   

C#

 
AnswerRe: Why my .NET application is crashing?! Pin
Pete O'Hanlon27-Oct-15 0:00
mvePete O'Hanlon27-Oct-15 0:00 
AnswerRe: Why my .NET application is crashing?! Pin
John Torjo27-Oct-15 1:45
professionalJohn Torjo27-Oct-15 1:45 
AnswerRe: Why my .NET application is crashing?! Pin
Dave Kreskowiak27-Oct-15 2:29
mveDave Kreskowiak27-Oct-15 2:29 
QuestionWorking on multithreading application Pin
Member 1132358526-Oct-15 23:39
Member 1132358526-Oct-15 23:39 
AnswerRe: Working on multithreading application Pin
Daniel Pfeffer27-Oct-15 1:23
professionalDaniel Pfeffer27-Oct-15 1:23 
GeneralRe: Working on multithreading application Pin
BillWoodruff27-Oct-15 3:29
professionalBillWoodruff27-Oct-15 3:29 
GeneralRe: Working on multithreading application Pin
Daniel Pfeffer27-Oct-15 4:05
professionalDaniel Pfeffer27-Oct-15 4:05 
AnswerRe: Working on multithreading application Pin
Foothill27-Oct-15 4:30
professionalFoothill27-Oct-15 4:30 
One way is to put your worker thread in an infinite loop of sorts, kind of like a thread pool would. The loop needs to have clear paths to terminate the thread in any event.
You'll also need to use Wait Handles

C#
class ControllableThread
{
 Thread _thread;
 Action _task;
 bool _shutdown;
 ManualResetEvent[] _resetEvents

 // Implementation code here

 public void ThreadProc()
 {
  while (!_shutdown)
  {
   WaitHandle.WaitAny(_resetEvents);
   if (_task != null)
   {
    _task();
   }
  }
 }
}


Now this example is an oversimplification but it can point in the right direction. The Wait Handles act as crossing guards that allow the thread to execute whatever method is set to the _task variable and hold the thread's execution until their state is changed.
AnswerRe: Working on multithreading application Pin
Gerry Schmitz27-Oct-15 7:23
mveGerry Schmitz27-Oct-15 7:23 
Questionnew to C# Pin
Member 1206164726-Oct-15 18:39
Member 1206164726-Oct-15 18:39 
AnswerRe: new to C# Pin
Garth J Lancaster26-Oct-15 19:34
professionalGarth J Lancaster26-Oct-15 19:34 
AnswerRe: new to C# Pin
John Torjo26-Oct-15 19:51
professionalJohn Torjo26-Oct-15 19:51 
AnswerRe: new to C# Pin
OriginalGriff26-Oct-15 22:50
mveOriginalGriff26-Oct-15 22:50 
AnswerRe: new to C# Pin
BillWoodruff27-Oct-15 1:43
professionalBillWoodruff27-Oct-15 1:43 
Questionchart axis offset when reflesh data Pin
smallkubi26-Oct-15 1:29
smallkubi26-Oct-15 1:29 
AnswerRe: chart axis offset when reflesh data Pin
John Torjo26-Oct-15 6:06
professionalJohn Torjo26-Oct-15 6:06 
QuestionI have this code in C # more people basic_info returns 0!? Can someone help me? Pin
Member 1208599525-Oct-15 9:05
Member 1208599525-Oct-15 9:05 
AnswerRe: I have this code in C # more people basic_info returns 0!? Can someone help me? Pin
BillWoodruff25-Oct-15 9:13
professionalBillWoodruff25-Oct-15 9:13 
GeneralRe: I have this code in C # more people basic_info returns 0!? Can someone help me? Pin
Member 1208599525-Oct-15 9:24
Member 1208599525-Oct-15 9:24 
GeneralRe: I have this code in C # more people basic_info returns 0!? Can someone help me? Pin
BillWoodruff25-Oct-15 11:25
professionalBillWoodruff25-Oct-15 11:25 
AnswerRe: I have this code in C # more people basic_info returns 0!? Can someone help me? Pin
Member 1208599525-Oct-15 9:18
Member 1208599525-Oct-15 9:18 
GeneralRe: I have this code in C # more people basic_info returns 0!? Can someone help me? Pin
Member 1208599525-Oct-15 9:23
Member 1208599525-Oct-15 9:23 
GeneralRe: I have this code in C # more people basic_info returns 0!? Can someone help me? Pin
Pete O'Hanlon25-Oct-15 12:06
mvePete O'Hanlon25-Oct-15 12:06 
GeneralRe: I have this code in C # more people basic_info returns 0!? Can someone help me? Pin
Member 1208599525-Oct-15 12:16
Member 1208599525-Oct-15 12:16 
GeneralRe: I have this code in C # more people basic_info returns 0!? Can someone help me? Pin
Pete O'Hanlon25-Oct-15 12:48
mvePete O'Hanlon25-Oct-15 12:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.