Click here to Skip to main content
15,904,494 members
Home / Discussions / C#
   

C#

 
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 
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 
GeneralRe: Enable foldering ? Pin
Ahmed R El Bohoty27-Apr-07 12:22
Ahmed R El Bohoty27-Apr-07 12:22 

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.