multithreading

How to automatically call a method in a static class on application start up and close down?

I'm writing a static class for logging to be used across my developed solution. There are several components that will use it such as a console application, ASP.NET application, etc... For the logging to work, it needs to do some initial startup configuration before it can be used, and also some clean up when each application has finish...

Threading Model

Is there a threading model that works something like the following: while thread = nextAvailableThread(): thread.doWork(data) Such that when a thread is finished it triggers nextAvailableThread() to return this thread that just finished. This model would make distributing uneven data chunks between threads much easier as you could j...

.NET Threading Model and Application.DoEvents vs. Thread.Sleep

We have a desktop application that performs a pretty rigorous set of calculations in a background thread. Portions of this calculation are performed in an unmanaged library that we access through interop. What we are finding is that, when we kick off the calculation, the UI thread becomes unresponsive for the duration of the calculatio...

in .NET, How do I set STAThread when I'm running a form in an additional thread?

I'm running a form in a second thread. If I do Ctrl-C to copy text on the clipboard, I get an Exception, "Current thread must be set to a single thread apartment (STA) before OLE calls can be made. (Using the clipboard involves OLE apparently). Putting the [STAThread] with my thread proc, which is the entry point of my second thread ...

Descendant of TThread, accessing properties from main thread

I have a class which is a descendant of TThread. I have some public properties that are read only. Will I run into problems if my main thread reads those values while the thread is active? ...

Is there any way in Java to log *every* Thread interrupt?

I would like to somehow log every time Thread.interrupt() is called, logging which Thread issued the call (and its current stack) as well as identifying information about which Thread is being interrupted. Is there a way to do this? Searching for information, I saw someone reference the possibility of implementing a security manager. ...

How does multithreading on iPhone OS work? How do I use it?

I am curious about threads on iPhone. Are they easy to establish and to maintain? How does it work on the iPhone? Is it real multithreading? ...

Will zipping a directory in Java affect other processes using the same files?

I'm using the java.util.zip library and ZipOutputStream in order to create a zip file of a directory and all the files and directories under it. In my application, it is likely that another thread could be accessing these same files during the compression. I'm not an expert on file compression (or thread-safety, for that matter) so my ...

What is the difference between mutex and critical section?

Please explain from Linux, Windows perspectives? I am programming in C#, would these two terms make a difference. Please post as much as you can, with examples and such.... Thanks ...

How to Perform Asynchronous File Reads in C# 2.0?

I have an application which needs to loop through all the lines in text files, over gigabytes in size. Some of these files have 10's or 100's of millions of lines. An example of my current (and synchronous) reading, looks something like... using (FileStream stream = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.R...

When to use the keyword "static" in C++class?

Code static void MyClass::ThreadEntryStatic() { //... } void MyClass::Begin() { CreateThread(..,ThreadEntryStatic,..); } In which condition we should use the static in class ? ...

CPU Usage Spikes in WebSphere 6.1

First, just a bit of background: One of our customers is experiencing CPU usage spikes for WebSphere instances running one of our web apps (other instances with other apps are fine). They have a test environment and a live environment (both iSeries) which both experience the problem - with a single app per instance setup. We have deploy...

Thread-safe blocking queue implementation on .NET

Hello. I'm looking for an implementation of thread-safe blocking queue for .NET. By "thread-safe blocking queue" I mean: - thread-safe access to a queue where Dequeue method call blocks a thread untill other thread puts (Enqueue) some value. By the moment I'v found this one: http://www.eggheadcafe.com/articles/20060414.asp (But it's for...

Java multi-threading & Safe Publication

After reading "Java concurrent in practice" and "OSGI in practice" I found a specific subject very interesting; Safe Publication. The following is from JCIP: "To publish an object safely, both the reference to the object and the object's state must be made visible to other threads at the same time. A properly constructed object can be s...

Stop program execution until threads complete

I have a console application that inits 4 theads to perform a long task. I want my program to wait until the threads are complete, and then complete the program execution. Is there a way to stop the program from executing, letting the threads complete their job? ...

Unlocking the critical section in case of non-C++ exceptions

I have a object of CCriticalSection in my class to synchronize the exceptions to a method. I use it with CSingleLock object like this: void f() { try { CSingleLock lock(&m_synchronizer, TRUE); ..... ..... } catch(SomeException ) { } catch(...) { } } The critical section object is properly unlock...

C#: Crash on ManualResetEvent

Hello, I wrote my code using this article at msdn as a primary helper My code: private ManualResetEvent _AllDone = new ManualResetEvent(false); internal void Initialize(int port,string IP) { IPEndPoint _Point = new IPEndPoint(IPAddress.Parse(IP), port); Socket _Accpt = new Socket(AddressFamily.InterNetwork...

C# Thread.Sleep waking immediately

I am using the code below Thread.Sleep(5); at the end of a while loop. To try and get a 5ms delay between iterations. Sometimes it sleeps for 16ms. This I understand and accept, since it depends on when the CPU gets around to servicing the thread. However once it has woken the next iteration it seems to wake immediately after the sle...

How to ensure that a winform closes in exactly X seconds

In my WinForms application, I need to pop up a little custom dialog that stays on the screen for X amount of seconds and then disappears. So I use a System.Threading.Timer to invoke the _dialog.Close() method once the appropriate amount of time has elapsed. This of course means that I have to do the whole "if InvokeRequired BeginInvoke...

WPF Canvas: Children.Add() hanging on background thread?

...or... "What evil in the depths of WPF have I awoken?" I'm creating a Canvas on a background thread and rendering it to a bitmap. I've had this working in production code for over a year now without problems. I do the following: create a Canvas object create a new NameScope object assign that NameScope to the Canvas draw whatever I...