Click here to Skip to main content
15,923,374 members
Home / Discussions / C#
   

C#

 
QuestionPublishing a console application? Pin
Goalie3529-Jul-08 4:14
Goalie3529-Jul-08 4:14 
AnswerRe: Publishing a console application? Pin
leppie29-Jul-08 4:48
leppie29-Jul-08 4:48 
AnswerRe: Publishing a console application? Pin
Mircea Puiu29-Jul-08 4:58
Mircea Puiu29-Jul-08 4:58 
QuestionMultiThread Programing Pin
LincolnGuimaraes29-Jul-08 3:58
LincolnGuimaraes29-Jul-08 3:58 
AnswerRe: MultiThread Programing Pin
Mircea Puiu29-Jul-08 4:47
Mircea Puiu29-Jul-08 4:47 
AnswerRe: MultiThread Programing Pin
Yosh_29-Jul-08 5:00
professionalYosh_29-Jul-08 5:00 
AnswerRe: MultiThread Programing Pin
Yosh_29-Jul-08 5:01
professionalYosh_29-Jul-08 5:01 
AnswerRe: MultiThread Programing Pin
Guffa29-Jul-08 6:34
Guffa29-Jul-08 6:34 
A while back I wrote a class named SynchronisedQueue[^] for parallel processing of Mandelbrot graphics.

The main thread could use it to send the jobs to the threads by simply adding it to the queue. The threads would periodically try to get something from the queue while they are idle.

The class for a thread could be something like:

public class WorkerThread {

   public volatile bool Contine;
   private SynchronisedQueue<Job> _jobs;

   public WorkerThread(SynchronisedQueue<Job> jobs) {
      Contine = true;
      _jobs = jobs;
   }

   public void Run() {
      while (Continue) {
         Job job;
         if (jobs.TryDequeue(out job)) {
            // handle the job
         } else {
            Thread.Sleep(100);
         }
      }
   }

}

The main thread creates a queue, then creates the objects for the worker threads and sends the queue along to the constructor.

If you need to send a result back from the worker thread to the main thread, you add another queue for the results. When the thread is done it just adds a result to the queue, and you have a timer in the main thread to look for results in the queue.

The code for dispatching the jobs gets really simple. There is no requesting of threads and handling the situation of waiting for a free thread, just throw the jobs in the queue, and the first thread that gets free grabs it. Smile | :)

Despite everything, the person most likely to be fooling you next is yourself.

AnswerRe: MultiThread Programing Pin
Joe Woodbury29-Jul-08 9:24
professionalJoe Woodbury29-Jul-08 9:24 
Questionjavascript for grid view checkbox Pin
umeshdaiya29-Jul-08 3:14
umeshdaiya29-Jul-08 3:14 
AnswerRe: javascript for grid view checkbox Pin
leppie29-Jul-08 4:51
leppie29-Jul-08 4:51 
QuestionCannot pass params! Any ideas? Pin
FruitBatInShades29-Jul-08 2:56
FruitBatInShades29-Jul-08 2:56 
AnswerRe: Cannot pass params! Any ideas? Pin
J4amieC29-Jul-08 3:00
J4amieC29-Jul-08 3:00 
GeneralRe: Cannot pass params! Any ideas? Pin
Luc Pattyn29-Jul-08 4:00
sitebuilderLuc Pattyn29-Jul-08 4:00 
GeneralRe: Cannot pass params! Any ideas? Pin
J4amieC29-Jul-08 4:27
J4amieC29-Jul-08 4:27 
GeneralRe: Cannot pass params! Any ideas? Pin
FruitBatInShades29-Jul-08 22:47
FruitBatInShades29-Jul-08 22:47 
QuestionRe: Cannot pass params! Any ideas? Pin
Luc Pattyn29-Jul-08 3:11
sitebuilderLuc Pattyn29-Jul-08 3:11 
QuestionHttp traffic from IE Pin
George_George29-Jul-08 2:31
George_George29-Jul-08 2:31 
AnswerRe: Http traffic from IE Pin
J4amieC29-Jul-08 2:45
J4amieC29-Jul-08 2:45 
GeneralRe: Http traffic from IE Pin
George_George29-Jul-08 3:15
George_George29-Jul-08 3:15 
QuestionDynamically Add Columns to Existing DataTable Pin
MumbleB29-Jul-08 2:20
MumbleB29-Jul-08 2:20 
AnswerRe: Dynamically Add Columns to Existing DataTable [modified] Pin
paas29-Jul-08 3:02
paas29-Jul-08 3:02 
GeneralRe: Dynamically Add Columns to Existing DataTable Pin
MumbleB29-Jul-08 3:08
MumbleB29-Jul-08 3:08 
GeneralRe: Dynamically Add Columns to Existing DataTable Pin
paas29-Jul-08 3:10
paas29-Jul-08 3:10 
AnswerRe: Dynamically Add Columns to Existing DataTable [modified] Pin
Tuwing.Sabado29-Jul-08 3:07
Tuwing.Sabado29-Jul-08 3:07 

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.