Click here to Skip to main content
15,914,392 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to use event to re-write this code segment? Pin
Christian Graus1-Jun-08 17:57
protectorChristian Graus1-Jun-08 17:57 
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 
George_George wrote:
But the Enqueue operation will be blocked since it is using a lock object to do synchronization, right? Means if worker thread is at the same time Dequeue, the person who Enqueues must wait.


No. It won't block. You know, acquiring a lock is pretty fast. If you look at that code carefully, you will find lock is used only to dequeue items, and it will be released immediately once dequeued. Program won't hold the lock until it finishes executing the job. So it executes in a nonblocking fashion.

George_George wrote:
Does using event (as showed in the document you referred) has better performance compared with my alternative method?


The example which I showed utilizes CPU well. It won't create much threads for processing each task. It will use the existing threads to spin between the tasks. A free thread will be allocated to process the next task.

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.

According to your code, when a task is processed, it is not checking the stop flag. So it won't exit until the currently processing task ends. Right ? Also it will block the thread until it finishes the operation, so you can't guarantee that it will be executed in each 1 second. Correct me if I got you wrong.

All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia

How to use google | Ask smart questions

GeneralRe: how to use event to re-write this code segment? Pin
George_George3-Jun-08 1:56
George_George3-Jun-08 1:56 
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 

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.