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

C#

 
AnswerRe: Question about DirectX.Sound. Pin
Mycroft Holmes12-Apr-09 14:47
professionalMycroft Holmes12-Apr-09 14:47 
QuestionCan operators be overloaded for built-in value types Pin
Winkles12-Apr-09 12:19
Winkles12-Apr-09 12:19 
AnswerRe: Can operators be overloaded for built-in value types Pin
Colin Angus Mackay12-Apr-09 12:43
Colin Angus Mackay12-Apr-09 12:43 
AnswerRe: Can operators be overloaded for built-in value types Pin
DaveyM6912-Apr-09 20:53
professionalDaveyM6912-Apr-09 20:53 
QuestionMaximize Problem in MDI Form. Pin
hdv21212-Apr-09 10:49
hdv21212-Apr-09 10:49 
AnswerRe: Maximize Problem in MDI Form. Pin
sajid.salim.khan12-Apr-09 18:32
sajid.salim.khan12-Apr-09 18:32 
GeneralRe: Maximize Problem in MDI Form. Pin
hdv21213-Apr-09 9:24
hdv21213-Apr-09 9:24 
Questionmonitor.pulse Pin
kyus9412-Apr-09 9:38
kyus9412-Apr-09 9:38 
Following explanation is from msdn document
The Monitor class does not maintain state indicating that the Pulse method has been called. Thus, if you call Pulse when no threads are waiting, the next thread that calls Wait blocks as if Pulse had never been called.

If not threads is wating then pluse is ignored??

I have following code ...it starts 3 threads and enques 12 tasks before even 3 threads finished work that means for next 9 pulses there are not threads waiting. Still all the tasks get processed. According to documentatiion next 9 pulses should be ignored as if they never happened. Did I misunderstood the documentation.

using System;
using System.Threading;
using System.Collections.Generic;
namespace ThreadingConsole
{
public class TaskQueue : IDisposable
{
object locker = new object();
Thread[] workers;
public Queue<string> taskQ = new Queue<string>();

public TaskQueue(int workerCount)
{
workers = new Thread[workerCount];

// Create and start a separate thread for each worker
for (int i = 0; i < workerCount; i++)
(workers[i] = new Thread(Consume)).Start();
}

public void Dispose()
{
// Enqueue one null task per worker to make each exit.
foreach (Thread worker in workers) EnqueueTask(null);
}

public void EnqueueTask(string task)
{
lock (locker)
{
taskQ.Enqueue(task); // We must pulse because we're
Console.WriteLine("START : " + task + " " + DateTime.Now.ToString()); // Perform task.
Monitor.Pulse(locker); // changing a blocking condition.
}

}

void Consume()
{
while (true) // Keep consuming until
{ // told otherwise
string task;
lock (locker)
{
while (taskQ.Count == 0) Monitor.Wait(locker);
task = taskQ.Dequeue();
}
if (task == null) return; // This signals our exit
Thread.Sleep(10000); // Simulate time-consuming task
Console.WriteLine("END : " + task + " " +DateTime.Now.ToString()); // Perform task.
}
}
public void Start()
{
string[] sTasks = GetNewWork();
Console.WriteLine("Start Enquing Tasks : " + DateTime.Now.ToString());
foreach (string s in sTasks)
this.EnqueueTask(s);
Console.WriteLine("Finished Enquing Tasks : " + DateTime.Now.ToString());
}

string[] GetNewWork()
{
return new string[] { "AAAAA", "BBBBB", "CCCCC", "DDDD", "AAAAA1", "BBBBB1", "CCCCC1", "DDDD1", "AAAAA2", "BBBBB2", "CCCCC2", "DDDD2", "AAAAA3", "BBBBB3", "CCCCC3", "DDDD3" };
}
}
}


class Program
{
static void Main(string[] args)
{
using (TaskQueue queue = new TaskQueue(3))
{
queue.Start();
Console.ReadLine();
}
}
}

kyus

AnswerRe: monitor.pulse Pin
Nicholas Butler12-Apr-09 9:47
sitebuilderNicholas Butler12-Apr-09 9:47 
GeneralRe: monitor.pulse Pin
ykcontact22-Apr-09 5:08
ykcontact22-Apr-09 5:08 
GeneralRe: monitor.pulse Pin
Nicholas Butler22-Apr-09 5:30
sitebuilderNicholas Butler22-Apr-09 5:30 
QuestionDesigning form Pin
Rajdeep.NET is BACK12-Apr-09 8:52
Rajdeep.NET is BACK12-Apr-09 8:52 
QuestionSending byte array(data) to a URL with POST or GET Pin
Member 441789212-Apr-09 6:57
Member 441789212-Apr-09 6:57 
AnswerRe: Sending byte array(data) to a URL with POST or GET Pin
harold aptroot12-Apr-09 7:09
harold aptroot12-Apr-09 7:09 
GeneralRe: Sending byte array(data) to a URL with POST or GET Pin
Member 441789212-Apr-09 7:17
Member 441789212-Apr-09 7:17 
GeneralRe: Sending byte array(data) to a URL with POST or GET Pin
harold aptroot12-Apr-09 7:43
harold aptroot12-Apr-09 7:43 
AnswerRe: Sending byte array(data) to a URL with POST or GET Pin
Luc 64801112-Apr-09 8:23
Luc 64801112-Apr-09 8:23 
GeneralRe: Sending byte array(data) to a URL with POST or GET Pin
Member 441789212-Apr-09 9:10
Member 441789212-Apr-09 9:10 
GeneralRe: Sending byte array(data) to a URL with POST or GET Pin
Luc 64801112-Apr-09 9:33
Luc 64801112-Apr-09 9:33 
Questionthreading question Pin
Rafone12-Apr-09 6:45
Rafone12-Apr-09 6:45 
AnswerRe: threading question Pin
Luc 64801112-Apr-09 7:05
Luc 64801112-Apr-09 7:05 
GeneralRe: threading question Pin
Rafone12-Apr-09 8:42
Rafone12-Apr-09 8:42 
Questionhow to make admin form Pin
manika12312-Apr-09 6:34
manika12312-Apr-09 6:34 
AnswerRe: how to make admin form Pin
EliottA12-Apr-09 6:35
EliottA12-Apr-09 6:35 
QuestionWhat is the base for making chat program Pin
E_Gold12-Apr-09 4:32
E_Gold12-Apr-09 4:32 

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.