multithreading

Is there a way to determine when a .NET thread terminates?

I'm trying to find out whether there is a way to reliably determine when a managed thread is about to terminate. I'm using a third-party library that includes support for PDF documents and the problem is that in order to use the PDF functionality, I have to explicitly initialize the PDF component, do the work, then explicitly uninitiali...

What is the difference between ManualResetEvent and AutoResetEvent in .net?

I have read the docs on this and I think I understand. Auto resets when the code passes through event.WaitOne() but manual does not. Is this correct? ...

.NET equivalent to Java thread groups?

I'm trying to monitor the states of a group of threads in a Microsoft.NET application written in C#. I'd like to be able to also monitor any child threads spawned by the original threads. In Java, you can assign threads to a thread group, and their children will also belong to the group. Is there an equivalent in .NET? I briefly looked...

Volatile vs. Interlocked vs. lock

Let's say that a class has a public int counter field that is accessed by multiple threads. This int is only incremented or decremented. To increment this field, which approach should be used, and why? lock(this.locker) this.counter++; Interlocked.Increment(ref this.counter); Change the access modifier of counter to public volatile ...

Another locking question

I'm trying to get my multithreading understanding locked down. I'm doing my best to teach myself, but some of these issues need clarification. I've gone through three iterations with a piece of code, experimenting with locking. In this code, the only thing that needs locking is this.managerThreadPriority. First, the simple, procedura...

What is function in Delphi to get the current executing thread?

I want a function like GetCurrentThread which returns a TThread object of the current executing thread. I know there is a Win32 API call GetCurrentThread, but it returns the thread Id. If there is a possibility to get TThread object from that ID that's also fine. ...

How to detect the number of context switches that occurred while running C# code?

From C#, is it possible to detect the number of context switches that occurred while executing a block of code on a particular thread? Ideally, I'd like to know how many times and what CPU my thread code was scheduled on. I know I can use tools like Event Tracing for Windows and the associated viewers, but this seemed a bit complicated ...

Get all items from thread Queue

Hello, I have one thread that writes results into a Queue. In another thread (GUI), I periodically (in the IDLE event) check if there are results in the queue, like this: def queue_get_all(q): items = [] while 1: try: items.append(q.get_nowait()) except Empty, e: break return items ...

Recommended Multithreading Book

I want to read a good book about multithreading and parallelism. I have a primarily .NET background but I think I would prefer a book focused on first principles and working into general patterns and algorithms and being overall less technology specific. Obviously a discussion of the kind of low-level system architecture issues that the...

What does the term "input-synchronized calls" mean?

I found this in an article on Multithreaded Apartments, but can’t find a definition for “input-synchronized calls”. (Article is at http://msdn.microsoft.com/en-us/library/ms693421(VS.85).aspx) As used in the article - Multithreaded apartments cannot make input-synchronized calls What are “input-synchronized" calls? Thanks ...

Looking for MacOS Threaded Networking sample code

My code needs to run all networking routines in a separate NSThread. I have got a library, which I pass a callback routine for communication: my thread code library my callback (networking) library my thread code My callback routine must POST some data to an HTTP server (NSURLConnection), wait for the answer (start a N...

Windows Forms: A modal form that gets opened/closed by the application rather than the user?

I have what I believe to be a fairly well structured .NET 3.5 forms application (Unit Tests, Dependency Injection, SoC, the forms simply relay input and display output and don't do any logic, yadda yadda) I am just missing the winforms knowledge for how to get this bit to work. When a connection to the database is lost - a frequent occu...

When would I use AutoResetEvent and ManualResetEvent instead of Monitor.Wait/Monitor.Pulse in .net?

They both seem to fulfil the same purpose. When would I chose one over the other? ...

My form doesn't properly display when it is launched from another thread

Hello everybody! Here's the situation: I'm developing a simple application with the following structure: FormMain (startup point) FormNotification CompleFunctions Right? Well, in FormMain I have the following function: private void DoItInNewThread(ParameterizedThreadStart pParameterizedThreadStart, object pParameters, ThreadPriorit...

Is JavaScript single threaded? If not, how do I get synchronized access to shared data?

I have a web page with DIVs with a mouseover handler that is intended to show a pop-up information bubble. I don't want more than one info bubble to be visible at a time. But when the user moves the mouse rapidly over two items, I sometimes get two bubbles. This should not happen, because the code for showing a pop-up cancels the previou...

Why do I get an error after closing my Winforms application?

When I run my vs.net winforms application by clicking F5 (debug mode), after I click on the close (which calls Application.Exit();), after a few seconds I get an error that says: cannot acess a disposed object: Object name 'SampleForm'. A bit of background, I have another thread that runs every x seconds. My guess is that when I c...

Generic GDI+ Error

I have a Form being launched from another form on a different thread. Most of the time it works perfectly, but I get the below error from time to time. Can anyone help? at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) at System.Drawing.Bitmap..ctor(Int32 width, Int32 height) at System.Drawing.Icon.ToBitmap()...

On Win32 how do you move a thread to another cpu core?

I'd like to make sure that a thread is moved to a specific cpu core & can never be moved from it by the scheduler. There's a SetThreadAffinityMask() call but there's no GetThreadAffinityMask(). The reason I need this is because high resoultion timers will get messed up if the scheduler moves that thread to another cpu. ...

Make your collections thread-safe?

When designing a collection class, is there any reason not to implement locking privately to make it thread safe? Or should I leave that responsibility up to the consumer of the collection? ...

What tools/diagrams do you use for modelling multithreaded systems?

I'm sitting there every time I model my systems, thinking, there must be a better way to model concurrency than using UML activity diagrams. Please share your thoughts. What's your favourite tool or format for modelling and getting a clear understanding of how to build a concurrent system? ...