Click here to Skip to main content
15,896,329 members
Home / Discussions / C#
   

C#

 
AnswerRe: PropertyGrid - how to apply changes? Pin
Dan_P2-May-05 15:03
Dan_P2-May-05 15:03 
AnswerRe: PropertyGrid - how to apply changes? Pin
Mathew Hall2-May-05 15:03
Mathew Hall2-May-05 15:03 
GeneralRe: PropertyGrid - how to apply changes? Pin
Anonymous3-May-05 10:00
Anonymous3-May-05 10:00 
GeneralRead only Outlookbar Pin
Member 19299502-May-05 12:43
Member 19299502-May-05 12:43 
GeneralRe: Read only Outlookbar Pin
MoustafaS2-May-05 13:14
MoustafaS2-May-05 13:14 
GeneralUrl navigation Pin
Adnan Siddiqi2-May-05 10:42
Adnan Siddiqi2-May-05 10:42 
GeneralRe: Url navigation Pin
leppie2-May-05 14:57
leppie2-May-05 14:57 
QuestionCancellable operation -- recommended practice? Pin
Judah Gabriel Himango2-May-05 9:42
sponsorJudah Gabriel Himango2-May-05 9:42 
I've got some long-running operation that could be cancelled by the user. The way I'm doing it is

1. launch a second thread to do the entire operation.
2. when the second thread comes to the long-running piece of the operation, it launches a 3rd thread
3. the second thread monitors the 3rd thread, waiting for it to complete, while also monitoring if the user has cancelled.

My code looks something similar to

void DoHeavy()
{
    EatCpuForTwoMinutes();
}

void DoEntireOperation(ICancellable cancelFlag)
{
   ...
   // Do long-running piece on another thread
   ThreadStart heavyMethod = new ThreadStart(DoHeavy);
   IAsyncResult result = heavyMethod.BeginInvoke(null, null);
   
   // Wait here and watch for cancellation.
   while(result.IsCompleted == false)
   {
      if(cancelFlag.IsCancelPending) break;
      else Thread.Sleep(250);
   }
...
}


I feel like Thread.Sleep is a total waste, since the operation could complete before 250 milliseconds is up. I also feel this is inducing too much overhead, constantly checking whether the delegate is completed. Is there a better way to do this?

Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango


AnswerRe: Cancellable operation -- recommended practice? Pin
Marc Clifton2-May-05 10:56
mvaMarc Clifton2-May-05 10:56 
GeneralRe: Cancellable operation -- recommended practice? Pin
Judah Gabriel Himango2-May-05 11:03
sponsorJudah Gabriel Himango2-May-05 11:03 
QuestionPassing methods to ThreadStart - Possible? Pin
stan282-May-05 8:52
stan282-May-05 8:52 
AnswerRe: Passing methods to ThreadStart - Possible? Pin
Judah Gabriel Himango2-May-05 9:05
sponsorJudah Gabriel Himango2-May-05 9:05 
AnswerRe: Passing methods to ThreadStart - Possible? Pin
Marc Clifton2-May-05 10:52
mvaMarc Clifton2-May-05 10:52 
AnswerRe: Passing methods to ThreadStart - Possible? Pin
leppie2-May-05 14:29
leppie2-May-05 14:29 
GeneralGeneric Hashtable Pin
Anonymous2-May-05 8:48
Anonymous2-May-05 8:48 
GeneralRe: Generic Hashtable Pin
Marc Clifton2-May-05 10:53
mvaMarc Clifton2-May-05 10:53 
GeneralRe: Generic Hashtable Pin
Anonymous3-May-05 5:09
Anonymous3-May-05 5:09 
GeneralRe: Generic Hashtable Pin
leppie2-May-05 14:46
leppie2-May-05 14:46 
GeneralOle Server Pin
BigAnyon2-May-05 5:58
BigAnyon2-May-05 5:58 
GeneralVisual style icons / bitmaps Pin
Anonymous2-May-05 5:45
Anonymous2-May-05 5:45 
GeneralRe: Visual style icons / bitmaps Pin
Judah Gabriel Himango2-May-05 7:05
sponsorJudah Gabriel Himango2-May-05 7:05 
GeneralRe: Visual style icons / bitmaps Pin
MoustafaS2-May-05 8:49
MoustafaS2-May-05 8:49 
GeneralEasy file I/O Pin
briggs_w2-May-05 4:58
briggs_w2-May-05 4:58 
GeneralRe: Easy file I/O Pin
Heath Stewart2-May-05 5:11
protectorHeath Stewart2-May-05 5:11 
GeneralRe: Easy file I/O Pin
Marc Clifton2-May-05 5:24
mvaMarc Clifton2-May-05 5:24 

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.