Click here to Skip to main content
15,909,440 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to use event to re-write this code segment? Pin
George_George1-Jun-08 18:32
George_George1-Jun-08 18:32 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult2-Jun-08 6:22
mvePIEBALDconsult2-Jun-08 6:22 
GeneralRe: how to use event to re-write this code segment? Pin
N a v a n e e t h1-Jun-08 20:03
N a v a n e e t h1-Jun-08 20:03 
GeneralRe: how to use event to re-write this code segment? Pin
George_George2-Jun-08 1:08
George_George2-Jun-08 1:08 
GeneralRe: how to use event to re-write this code segment? Pin
N a v a n e e t h2-Jun-08 1:23
N a v a n e e t h2-Jun-08 1:23 
GeneralRe: how to use event to re-write this code segment? Pin
George_George2-Jun-08 1:48
George_George2-Jun-08 1:48 
GeneralRe: how to use event to re-write this code segment? Pin
N a v a n e e t h2-Jun-08 3:03
N a v a n e e t h2-Jun-08 3:03 
GeneralRe: how to use event to re-write this code segment? Pin
George_George3-Jun-08 1:56
George_George3-Jun-08 1:56 
Thanks for your great reply, N a v a n e e t h!


Three more comments after some thinking. Smile | :)

1.

N a v a n e e t h wrote:
only to dequeue items


No. When Enqueue, the lock is still used.

Here is the code. Any comments?

public void EnqueueTask (string task) {
  lock (locker) tasks.Enqueue (task);
  wh.Set();
}


2.

N a v a n e e t h wrote:
It won't create much threads for processing each task. It will use the existing threads to spin between the tasks.


Which solution do you compare to when you mention "create much threads"? In my case, I only create one thread in the very first post.

If I use timer, then each time, the timer will create a new worker thread or reuse previous one?

3.

N a v a n e e t h wrote:
Will the steps you provided satisfy your requirement ? As I understood from the previous messages, you are trying to execute a task before the previous task completes. I mean you need to execute it in each 1 second without blocking. If it is the case, looks like the steps you provided won't satisfy the requirement.


Sorry my English is not very good. Smile | :)

My requirement is to complete the current task before execute next task, and between each task execution iteration, sleep 1 second so that system could have more chances to do other things. Could you help to review my previous solution again to see whether it could achive requirement please?


regards,
George
GeneralRe: how to use event to re-write this code segment? Pin
N a v a n e e t h3-Jun-08 7:10
N a v a n e e t h3-Jun-08 7:10 
GeneralRe: how to use event to re-write this code segment? Pin
George_George3-Jun-08 15:30
George_George3-Jun-08 15:30 
GeneralRe: how to use event to re-write this code segment? Pin
N a v a n e e t h3-Jun-08 15:42
N a v a n e e t h3-Jun-08 15:42 
GeneralRe: how to use event to re-write this code segment? Pin
George_George3-Jun-08 18:25
George_George3-Jun-08 18:25 
GeneralRe: how to use event to re-write this code segment? Pin
N a v a n e e t h4-Jun-08 3:51
N a v a n e e t h4-Jun-08 3:51 
GeneralRe: how to use event to re-write this code segment? Pin
George_George4-Jun-08 20:26
George_George4-Jun-08 20:26 
GeneralRe: how to use event to re-write this code segment? Pin
N a v a n e e t h5-Jun-08 6:47
N a v a n e e t h5-Jun-08 6:47 
GeneralRe: how to use event to re-write this code segment? Pin
George_George5-Jun-08 14:51
George_George5-Jun-08 14:51 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult1-Jun-08 17:49
mvePIEBALDconsult1-Jun-08 17:49 
GeneralRe: how to use event to re-write this code segment? Pin
George_George1-Jun-08 18:34
George_George1-Jun-08 18:34 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult1-Jun-08 19:12
mvePIEBALDconsult1-Jun-08 19:12 
GeneralRe: how to use event to re-write this code segment? Pin
George_George1-Jun-08 19:17
George_George1-Jun-08 19:17 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult1-Jun-08 19:26
mvePIEBALDconsult1-Jun-08 19:26 
GeneralRe: how to use event to re-write this code segment? Pin
George_George2-Jun-08 0:52
George_George2-Jun-08 0:52 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult2-Jun-08 9:07
mvePIEBALDconsult2-Jun-08 9:07 
GeneralRe: how to use event to re-write this code segment? Pin
George_George3-Jun-08 1:36
George_George3-Jun-08 1:36 
GeneralRe: how to use event to re-write this code segment? Pin
PIEBALDconsult3-Jun-08 17:59
mvePIEBALDconsult3-Jun-08 17:59 

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.