multithreading

Exception handling in producer-consumer pattern using TPL in C#

I am using TPL support to implement a multithreading producer-consumer pattern in C#. With the handy BlockingCollection and Task classes, the job is easy, until I need to handle exceptions. As we all know, the consumer Tasks objects will be blocked when there is no item in BlockingCollection for consumption and to prevent those Tasks fr...

How to tell producer to not wait in producer-consumer pattern using C# TPL

I implements a producer-consumer pattern using C#'s TPL. The scenario is described as below. I have a task who produces jobs to a BlockingCollection. The collection has a capacity limit, say, 3 jobs maximally. I have two consumer tasks who try to get jobs from the collection and execute them. I also implement a cancellation to the produ...

Threads for peer to peer communication

I am trying to make a multi-player network game. Each player is represented by a rectangle on the screen. I am using OpenGL for the graphics and also the user input (commands like MOVE-LEFT, MOVE-RIGHT etc ) will be handled by it (or GLUT or sumthing). I have the following architecture for the game. There are 4 players(nodes) in the g...

Running multiple C# Task Async

Hi normally I would do this with a Background Worker, but I would like to do it with C# Task instead, just to understand Task better. The thing is that I have a class with the following properties private int _number1; public int Number1 { get { return _number1; } set { _number1 = value; OnPropertyChanged("N...

Determine what is blocking UI thread

Hi All I am working on a rather large .NET WPF real-time application. The application is working great and as expected, except for one BIG issue - UI Update is slow. This application is highly event driven, there are events raised all over for all sorts of things - through these events the UI is updated. One or many of these events is...

STA thread Abort Exception

I am initializing a thread as static thread as shown below Thread GenerateKeywords; private void btnStart_Click(object sender, EventArgs e) { //Initializes the Test Thread Test = new Thread(TestMethod); //Sets the apartment state to Static Test.SetApartmentState(ApartmentState.STA); //Starts the Gener...

Synchronize thread and a method with an object?

Hi, I have a method and a thread which I'd like to run in the following order: First the method should do something with an object, and then the thread should do something with the object. They share the same object. I have to synchronize them, but I am just meeting with Threads. How can I do that? private synchronized method() { //do s...

Android Thread details

I can create a class which extends Thread and overrides the run method with a loop. I then start it with myThread.start(), which create the OS thread and executes my run(). That's all good. However, I don't quite understand the details. I'll have a go at working this out using test code when I get the chance, but before then can anyone ...

Killing HttpWebRequest object using Thread.Abort

All, I am trying to cancel two concurrent HttpWebRequests using a method similar to the code below (shown in pseudo-ish C#). The Main method creates two threads which create HttpWebRequests. If the user wishes to, they may abort the requests by clicking a button which then calls the Abort method. private Thread first; private Thread s...

What happens to locks on objects passed to other threads?

I'm not quite sure how to word this, so I'll just paste my code and ask the question: private void remoteAction_JobStatusUpdated(JobStatus status) { lock (status) { status.LastUpdatedTime = DateTime.Now; doForEachClient(c => c.OnJobStatusUpdated(status)); OnJobStatusUpdated(status); } } private void doFo...

Dispatcher BeginInvoke Syntax

I have been trying to follow some WCF Data Services examples and have the following code: private void OnSaveCompleted(IAsyncResult result) { Dispatcher.BeginInvoke(() => { context.EndSaveChanges(result); }); } Which is called by the following: this.context.BeginSaveChanges(SaveChangesOptio...

Fork/Join task (jsr166y) and speed-up

I tried to speed up some toy examples code using jsr166y. I have not been able to reach any success, whatever the class/methods I used. I even tried the code featured in the IBM developer works paper without any success. Do you have some positive experience with this new framework ? Are there some better implementations ? Edit: I runne...

Runtime.getRuntime().exec() not launching process

I have a multi-threaded application that launches an external app to do data conversion in preparation for later parts of the application. I have an issue that when I set my thread count higher then 6 concurrent threads, the Runtime.getRuntime().exec() fails to launch the external application (I have also tried using ProcessBuilder with...

Algorithm to optimize # threads used in a calculation

I'm performing an operation, lets call it CalculateSomeData. CalculateSomeData operates in successive "generations", numbered 1..x. The number of generations in the entire run is fixed by the input parameters to CalculateSomeData and is known a priori. A single generation takes anywhere from 30 minutes to 2 hours to complete. Some of...

Exception caused by still running thread on back button press(Android)

I'm using code similar to whats below with the exception that the thread is started via a button press. When I press the button, the data at the url is grabbed and it switches me over to the other activity. The issue i'm having is when I'm at the other activity and hit the backbutton I get an Exception saying that the thread has already ...

C#: deadlock when invoking the UI thread from a worker thread

Hi all, I have a deadlock when I invoke the UI thread from a worker thread. Indeed, the worker thread is blocked on the invoke line: return (ucAvancementTrtFamille)mInterfaceTraitement.Invoke(d, new object[] { psFamille }); The weird thing is that the UI Thread (which, correct me if I'm wrong, is the main thread) is idle. Is there a...

WPF BackgroundWorker vs. Dispatcher

In my WPF application I need to do an async-operation then I need to update the GUI. And this thing I have to do many times in different moment with different oparations. I know two ways to do this: Dispatcher and BackgroundWorker. Because when I will chose it will be hard for me to go back, I ask you: what is better? What are the reaso...

Name of locking design pattern (the one with `internal' methods)

I recall a design pattern for handling locking issues in C++ (where some locks are not re-entrant) by separating methods into 'external' and 'internal' ones. External ones acquire locks and can call internal ones which in turn assert that locks are held. External ones cannot call other external ones (because that would deadlock) and for ...

Have python run script at X:00 am

Following up on, http://stackoverflow.com/questions/3553340/with-python-intervals-at-x00-repeat Using threading, How can I get a script to run starting at 8:00 am stop running at 5:00 pm The solution should be coded within python, and be portable tiA ...

Updating UI with Runnable & postDelayed not working with timer app

I have looked at every discussion and thread I can find on getting this to work but it is not. I have a simple timer that updates a text view (mTimeTextField in the example below). The mUpdateTimeTask run method is being executed correctly (every second) but the UI/text field is not being updated. I have code based on the info found her...