Click here to Skip to main content
15,898,134 members
Home / Discussions / C#
   

C#

 
GeneralRe: Adhoc networking using windows application in VS2005 Pin
alish061031-Mar-09 20:17
alish061031-Mar-09 20:17 
QuestionOpenFileDialog Pin
netJP12L31-Mar-09 4:22
netJP12L31-Mar-09 4:22 
AnswerRe: OpenFileDialog Pin
musefan31-Mar-09 4:30
musefan31-Mar-09 4:30 
AnswerRe: OpenFileDialog Pin
Giorgi Dalakishvili31-Mar-09 4:39
mentorGiorgi Dalakishvili31-Mar-09 4:39 
Questionc# 2005 add_In Excel 2003 Pin
sofianeannabi31-Mar-09 4:13
sofianeannabi31-Mar-09 4:13 
QuestionMulti-threading - Parallel Syncronization Pin
caksabre231-Mar-09 4:12
caksabre231-Mar-09 4:12 
AnswerRe: Multi-threading - Parallel Syncronization Pin
Luc Pattyn31-Mar-09 4:54
sitebuilderLuc Pattyn31-Mar-09 4:54 
AnswerRe: Multi-threading - Parallel Syncronization Pin
Ian Shlasko31-Mar-09 5:02
Ian Shlasko31-Mar-09 5:02 
Purely for organizational purposes, I would actually have a fourth thread controlling the other three, if possible. Threading problems can be difficult to debug, so keeping the code clean can sometimes be a big help...

Also, I would probably go with just basic EventWaitHandles

EventWaitHandle workerThreadStart[] = new EventWaitHandle[3];
EventWaitHandle workerThreadFinish[] = new EventWaitHandle[3];

// Controller thread:

while (true)
{
  for (int x = 0; x < 3; x++) workerThreadStart[x].Set();
  WaitHandle.WaitAll(workerThreadFinish);

  // Insert a delay if desired
}

// Each worker thread (# = 0, 1, or 2 for threads one, two, three):

while (true)
{
  workerThreadStart[#].WaitOne();

  try
  {
    // Do some task
  }
  catch (...)
  {
    // Remember, if you get an exception on a background thread, it may not display
  }
  finally 
  {
    // Even if we get an error, we want to set the EWH so as not to stall everything
    workerThreadFinish[#].Set();
  }
}


(Note: Just typed this out in here, not in a code editor, so might have typos or syntax problems - Just trying to give a rough idea anyway)


EDIT: Oh, and when you instantiate the EWH's, bring 'em up unsignaled and AutoReset.
AnswerRe: Multi-threading - Parallel Syncronization Pin
Alan N31-Mar-09 5:17
Alan N31-Mar-09 5:17 
GeneralRe: Multi-threading - Parallel Syncronization Pin
caksabre231-Mar-09 5:37
caksabre231-Mar-09 5:37 
Questionwhy button_click event raising 2 times? Pin
Narendra Reddy Vajrala31-Mar-09 3:43
Narendra Reddy Vajrala31-Mar-09 3:43 
AnswerRe: why button_click event raising 2 times? Pin
stancrm31-Mar-09 3:47
stancrm31-Mar-09 3:47 
GeneralRe: why button_click event raising 2 times? Pin
Narendra Reddy Vajrala31-Mar-09 3:57
Narendra Reddy Vajrala31-Mar-09 3:57 
GeneralRe: why button_click event raising 2 times? Pin
Ian Shlasko31-Mar-09 4:02
Ian Shlasko31-Mar-09 4:02 
GeneralRe: why button_click event raising 2 times? Pin
Narendra Reddy Vajrala31-Mar-09 4:12
Narendra Reddy Vajrala31-Mar-09 4:12 
AnswerRe: why button_click event raising 2 times? Pin
musefan31-Mar-09 3:54
musefan31-Mar-09 3:54 
GeneralRe: why button_click event raising 2 times? Pin
Narendra Reddy Vajrala31-Mar-09 3:57
Narendra Reddy Vajrala31-Mar-09 3:57 
GeneralRe: why button_click event raising 2 times? Pin
musefan31-Mar-09 4:02
musefan31-Mar-09 4:02 
GeneralRe: why button_click event raising 2 times? Pin
Narendra Reddy Vajrala31-Mar-09 4:16
Narendra Reddy Vajrala31-Mar-09 4:16 
GeneralRe: why button_click event raising 2 times? Pin
musefan31-Mar-09 4:21
musefan31-Mar-09 4:21 
GeneralRe: why button_click event raising 2 times? Pin
Narendra Reddy Vajrala31-Mar-09 4:32
Narendra Reddy Vajrala31-Mar-09 4:32 
GeneralRe: why button_click event raising 2 times? Pin
musefan31-Mar-09 4:34
musefan31-Mar-09 4:34 
GeneralRe: why button_click event raising 2 times? Pin
Colin Angus Mackay31-Mar-09 4:30
Colin Angus Mackay31-Mar-09 4:30 
GeneralRe: why button_click event raising 2 times? Pin
Narendra Reddy Vajrala31-Mar-09 4:40
Narendra Reddy Vajrala31-Mar-09 4:40 
GeneralRe: why button_click event raising 2 times? Pin
Ian Shlasko31-Mar-09 4:44
Ian Shlasko31-Mar-09 4:44 

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.