Click here to Skip to main content
15,908,020 members
Home / Discussions / C#
   

C#

 
QuestionUnit test of Asynchronous Block not happening Pin
Ashfaque Hussain28-Oct-15 0:57
Ashfaque Hussain28-Oct-15 0:57 
AnswerRe: Unit test of Asynchronous Block not happening Pin
Dave Kreskowiak28-Oct-15 4:02
mveDave Kreskowiak28-Oct-15 4:02 
AnswerRe: Unit test of Asynchronous Block not happening Pin
Nicholas Marty28-Oct-15 5:02
professionalNicholas Marty28-Oct-15 5:02 
GeneralRe: Unit test of Asynchronous Block not happening Pin
Ashfaque Hussain28-Oct-15 21:52
Ashfaque Hussain28-Oct-15 21:52 
QuestionFonts Activated through Win32 API AddFontResource is not available on the WPF control where as it is available in Documents and various application Pin
Prem9527-Oct-15 23:14
Prem9527-Oct-15 23:14 
SuggestionRe: Fonts Activated through Win32 API AddFontResource is not available on the WPF control where as it is available in Documents and various application Pin
Richard MacCutchan27-Oct-15 23:35
mveRichard MacCutchan27-Oct-15 23:35 
AnswerRe: Fonts Activated through Win32 API AddFontResource is not available on the WPF control where as it is available in Documents and various application Pin
Gerry Schmitz28-Oct-15 6:35
mveGerry Schmitz28-Oct-15 6:35 
QuestionNot allowed to change the 'ConnectionString' property. The connection's current state is connecting. Why I am getting this error? Pin
Member 1200209527-Oct-15 20:09
Member 1200209527-Oct-15 20:09 
AnswerRe: Not allowed to change the 'ConnectionString' property. The connection's current state is connecting. Why I am getting this error? Pin
John Torjo27-Oct-15 21:55
professionalJohn Torjo27-Oct-15 21:55 
QuestionPlugin 'System.Reflection.TargetInvocationException' While Passing Event Pin
jappi8827-Oct-15 7:04
jappi8827-Oct-15 7:04 
AnswerRe: Plugin 'System.Reflection.TargetInvocationException' While Passing Event Pin
Eddy Vluggen27-Oct-15 7:48
professionalEddy Vluggen27-Oct-15 7:48 
GeneralRe: Plugin 'System.Reflection.TargetInvocationException' While Passing Event Pin
John Torjo27-Oct-15 10:59
professionalJohn Torjo27-Oct-15 10:59 
GeneralRe: Plugin 'System.Reflection.TargetInvocationException' While Passing Event Pin
Eddy Vluggen27-Oct-15 12:36
professionalEddy Vluggen27-Oct-15 12:36 
QuestionWhy my .NET application is crashing?! Pin
Jassim Rahma26-Oct-15 23:42
Jassim Rahma26-Oct-15 23:42 
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 

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.