Click here to Skip to main content
15,895,256 members
Home / Discussions / C#
   

C#

 
AnswerRe: Thread Pool issues Pin
Jim Warburton27-Apr-07 8:17
Jim Warburton27-Apr-07 8:17 
QuestionDynamic Type should access protected Members of BaseClass [modified] Pin
BASHuss27-Apr-07 6:51
BASHuss27-Apr-07 6:51 
QuestionOpening a Document as ReadOnly Pin
Jonso27-Apr-07 6:44
Jonso27-Apr-07 6:44 
AnswerRe: Opening a Document as ReadOnly Pin
Scott Dorman27-Apr-07 7:27
professionalScott Dorman27-Apr-07 7:27 
AnswerRe: Opening a Document as ReadOnly Pin
GregD29-Apr-07 1:55
GregD29-Apr-07 1:55 
QuestionThreadPool.QueueUserWorkItem and checking if finished Pin
MrEyes27-Apr-07 5:51
MrEyes27-Apr-07 5:51 
AnswerRe: ThreadPool.QueueUserWorkItem and checking if finished Pin
Leslie Sanford27-Apr-07 6:18
Leslie Sanford27-Apr-07 6:18 
GeneralRe: ThreadPool.QueueUserWorkItem and checking if finished Pin
MrEyes27-Apr-07 6:31
MrEyes27-Apr-07 6:31 
That looks like it would do what I need, however considering I am a bit thick I am not sure what to use as the lockObject. Using the example in my first post the code has changed to something like this:

private static void StartQueue
{
  StringReader sr = new StringReader(rawData);
  string line = string.Empty;
  int jobCount = 0;
  while (((line = sr.ReadLine()) != null) && (this.allowQueuing))
  {
    ThreadPool.QueueUserWorkItem(new WaitCallback(DoMagicalThings), line);
    jobCount++
  }

  lock(lockObject)
  {
    while(jobCount > 0)
    {
      Monitor.Wait(lockObject);
    }
  }

  Console.WriteLine("All done");
}

private static void DoMagicalThings(object data)
{
  Console.WriteLine(data.ToString())

  lock(lockObject)
  {
    jobCount--;
    Monitor.Pulse(lockObject);
  }
}


An additional problem is that externally to this a user could click a Stop button, this should stop all threads and stop any further items being processed. Could I somehow use this Lock and Monitor functionality to do this?

In my original code, I had a simple class var bool that would be checked at the top of the worker method. If the value was false then the worker method would immediately return
GeneralRe: ThreadPool.QueueUserWorkItem and checking if finished Pin
Leslie Sanford27-Apr-07 6:51
Leslie Sanford27-Apr-07 6:51 
QuestionHow to create a custom .net control in C# that is a opengl application? Pin
sinosoidal27-Apr-07 5:42
sinosoidal27-Apr-07 5:42 
AnswerRe: How to create a custom .net control in C# that is a opengl application? Pin
sujithkumarsl27-Apr-07 6:20
sujithkumarsl27-Apr-07 6:20 
GeneralRe: How to create a custom .net control in C# that is a opengl application? Pin
sinosoidal29-Apr-07 23:08
sinosoidal29-Apr-07 23:08 
QuestionHow to clear printer buffer Pin
marianguru27-Apr-07 5:11
marianguru27-Apr-07 5:11 
AnswerRe: How to clear printer buffer Pin
Martin#29-Apr-07 9:34
Martin#29-Apr-07 9:34 
GeneralRe: How to clear printer buffer Pin
marianguru29-Apr-07 19:49
marianguru29-Apr-07 19:49 
GeneralRe: How to clear printer buffer Pin
PIEBALDconsult3-May-07 15:59
mvePIEBALDconsult3-May-07 15:59 
QuestionCreating drillthrough report using MS ReportViewer Pin
AndrusM27-Apr-07 4:50
AndrusM27-Apr-07 4:50 
Questionreusing the same port with .net remoting Pin
cignox127-Apr-07 4:44
cignox127-Apr-07 4:44 
QuestionShowing Animated Gif Pin
freshonlineMax27-Apr-07 4:43
freshonlineMax27-Apr-07 4:43 
AnswerRe: Showing Animated Gif Pin
Talal Sultan27-Apr-07 4:52
Talal Sultan27-Apr-07 4:52 
GeneralRe: Showing Animated Gif Pin
freshonlineMax27-Apr-07 6:23
freshonlineMax27-Apr-07 6:23 
AnswerRe: Showing Animated Gif Pin
Talal Sultan27-Apr-07 12:18
Talal Sultan27-Apr-07 12:18 
AnswerRe: Showing Animated Gif Pin
overfreeze27-Apr-07 12:39
overfreeze27-Apr-07 12:39 
QuestionEnable foldering ? Pin
Ahmed R El Bohoty27-Apr-07 4:29
Ahmed R El Bohoty27-Apr-07 4:29 
AnswerRe: Enable foldering ? Pin
Colin Angus Mackay27-Apr-07 4:47
Colin Angus Mackay27-Apr-07 4:47 

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.