multithreading

MSMQ for Managing Threads?!

I am building an application where I have inputs from printers over the network (on specific ports) and other files which are created into a folder locally or through the network. The user can create different threads to monitor different folders at the same time, as well as threads to handle the input from threes printers over the netwo...

Multithreading on a multi core machines not maxing CPU

I am working on maintaining someone else's code that is using multithreading, via two methods: 1: ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ReadData), objUpdateItem) 2: Dim aThread As New Thread(AddressOf LoadCache) aThread.Start() However, on a dual core machine, I am only getting 50% CPU utlilization, and on a dual...

How do I make cross-threaded calls to a ToolStripStatusLabel?

I tend to use a StatusStrip at the bottom of most of my applications for simple status updates and occasionally a progress bar. However, it appears ToolStripStatusLabels do not inherit from control, so they have no .Invoke, or .InvokeRequired. So how would I thread-safe make a call to change it's text property? Coded answers for poste...

C++ WxWidgets: Redirecting Stdout to a wxTextCtrl across mulitple threads

My application is a multi threaded app (using wxThreads). At the moment, the main thread along with it's child worker threads are outputting various messages to Stdout (using cout). I have a new frame/window with a wxTextCtrl, and would like to redirect all the StdOut messages in to it. GuiLogFrame *logframe; logframe = new...

C++ WxWidgets: Single log window for messages from Multiple Threads

What's the best/proper method to collect log messages from multiple threads and have them all be displayed using a window? (while the threads are running). I am currently trying to redirect stdout (cout) in to a wxTextCtrl but failing miserably when attempting to do so over multiple threads. Any help would be appreciated. ...

C#: Stopping a thread after an Exception

Hello! I have this code: Thread t = new Thread(() => UpdateImage(origin)); t.Name = "UpdateImageThread"; t.Start(); If method UpdateImage(origin) throw an exception, it is necessary to stop thread or it will be stoped after the exception? Thank you! ...

Ruby, how should I design a parser?

Hello, I'm writing a small parser for Google and I'm not sure what's the best way to design it. The main problem is the way it will remember the position it stopped at. During parsing it's going to append new searches to the end of a file and go through the file startig with the first line. Now I want to do it so, that if for some reaso...

C#: Initializing an event handler with a dummy

I've seen this sort of code some places: public event SomeEventHandler SomeEvent = (s, e) => { }; Is that a recommended way of doing things? What does it solve, and does it have any noteworthy side effects? Will I still have to do null checks? Or is that exactly what I don't have to do any more? Will garbage collection still work as i...

Javascript ManualReset event

ok i have a javascript api nothing fancy that has a function "x" that takes some parameters and a callback function. Is there a way i can wait for the callback in the function that calls it almost the same way manualresetevent works in C#. thanks ...

Are Generators Threadsafe?

I have a multithreaded program where I create a generator function and then pass it to new threads. I want it to be shared/global in nature so each thread can get the next value from the generator. Is it safe to use a generator like this, or will I run into problems/conditions accessing the shared generator from multiple threads? If...

Static Constructor & Singleton class

I have an object cache which implements the Singleton design pattern. My approach to singleton was always to lazy load the static instance when the property is first accessed. public static Widget Instance { get { if(instance==null) instance = new Widget(); return instance; } } However, I know that this ap...

Execute a delegate in the ui thread (using message pump).

I have a background thread that handles communication with an external service. Each time the background thread receives a message I'd like to pass it to the UI thread for further processing (displaying to user). Currently I've made a thread safe message queue that is pooled periodically in Timer.Tick and filled in background thread. Bu...

Threading using BackgroundWorker

I have a scenario. I have a list of user id's displayed on the windows form. As soon as I click one of the user id's I go and get the user details from the DB. To retain the responsiveness of the application, on selection changed event of the listbox, I create new BackgroundWorker(BW) objects and hit the DB. I show 'Searching user 'abc'....

Multi-threaded OpenGL Programming in Cocos2D-iPhone

In an attempt to create a loading bar for an iPhone game I'm developing (using Cocos2D), I wanted to use a multithreaded approach. One thread shows a loading screen and runs the main application event loop while a new thread silently loads all the Sprites in the background (through spriteWithFile) and then adds them to a layer. I creat...

How do I handle multiple key presses in a Java Applet?

I am teaching myself, from online tutorials, how to write games in Java. I am using Java Applets to create a Pong game. each paddle is controlled from different keys for 1v1 competition. this works fine if both users are hitting the keys at different times. but when one key is being held down and then another key is held down(ex: holdi...

System.Threading.Thread.Sleep - Any legit reason to have in production code?

I'm doing some code cleanup, and I came across a few instances of System.Threading.Thread.Sleep(2000); These are all in Button Click events. I can't think of any reason why this would be in production code? Am I missing something? EDIT -- Full Code Block (some things changed, but steps are the same) -- And yes, I think it sucks t...

Is there a limit on Background Workers? Technical or Common Sense...

In Program.cs I have the below method that is checking and the Syncing 5 SQL db's with the central server. Each one is separate from the other so I thought to speed up my program's load time by having them all run at the same time. Unfortunately it is very flaky working one time then not the next. The local DB is SQLExpress 2005 and the...

Random number clashes with same .Net code in different processes

Before I start, I want to point out that I'm pretty sure this actually happened. All my logs suggest that it did. I'd like to know whether I'm wrong and this is impossible, whether it's just incredibly unlikely (which I suspect), or if it's not that unlikely and I'm doing something fundamentally wrong. I have 4 instances of the same c...

Java Synchronized and Threads

I'm having issues with Synchronized not behaving the way i expect, i tried using volatile keyword also: Shared Object: public class ThreadValue { private String caller; private String value; public ThreadValue( String caller, String value ) { this.value = value; this.caller = caller; } public sync...

java synchronized issue

I'm having issues with Synchronized not behaving the way i expect, i tried using volatile keyword also: Shared Object: public class ThreadValue { private String caller; private String value; public ThreadValue( String caller, String value ) { this.value = value; this.caller = caller; } public synchronized String getValue() { ...