Click here to Skip to main content
15,920,896 members
Home / Discussions / C#
   

C#

 
AnswerRe: showing progress of a running Query Pin
overfreeze27-Apr-07 12:17
overfreeze27-Apr-07 12:17 
Question[Message Deleted] Pin
mahmoud wafy27-Apr-07 8:37
mahmoud wafy27-Apr-07 8:37 
AnswerRe: How Look over the field at the same time Pin
Wayne Phipps27-Apr-07 9:06
Wayne Phipps27-Apr-07 9:06 
AnswerI am very sorry to repeat the question twice Pin
mahmoud wafy27-Apr-07 13:45
mahmoud wafy27-Apr-07 13:45 
AnswerRe: I have one question Pin
Christian Graus27-Apr-07 10:46
protectorChristian Graus27-Apr-07 10:46 
QuestionIllustrated to my earlier question [modified] Pin
mahmoud wafy27-Apr-07 8:23
mahmoud wafy27-Apr-07 8:23 
QuestionThread Pool issues Pin
JEC456827-Apr-07 7:47
JEC456827-Apr-07 7:47 
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 
GeneralRe: ThreadPool.QueueUserWorkItem and checking if finished Pin
Leslie Sanford27-Apr-07 6:51
Leslie Sanford27-Apr-07 6:51 
You'll need to make the jobCount variable a member of the class instead of using a local variable as you did above. If you're using static methods, the variable will need to be a static variable.

As far as a lock object, what I usually do is just create a variable of type object:

private readonly object lockObject = new object();


It will need to be static if you're using it at the class level, i.e. in static methods.

MrEyes wrote:
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


This works. The structure of your thread method could be something like this:

private void ThreadMethod(object data)
{
    while(notStopped)
    {
        // Do stuff...
    }
 
    lock(lockObject)
    {
        jobCount--;
        Monitor.Pulse(lockObject);
    }
}


This way if the user clicks "Stop" and the notStopped variable is set to false, all of the threads break out of their loop, decrement the job counter, and signal that they're done.

You may want to make the jobCount and notStopped variables volatile so that when one thread updates them, their values are immediately updated, i.e. the compiler won't try to do any optimization in delaying their update.
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 

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.