multithreading

Problem using GDI+ with multiple threads (VB.NET)

I think it would be best if I just copy and pasted the code (it's very trivial). Private Sub Main() Handles MyBase.Shown timer.Interval = 10 timer.Enabled = True End Sub Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint e.Graphics.DrawImage(image, 0, ...

[Java] - Problem having my main thread sleeping

I'm in a Java class and our assignment is to let us explore threads in Java. So far so good except for this one this one problem. And I believe that could be because of my lack of understanding how Java threads work at the moment. I have the main thread of execution which spawns new threads. In the main thread of execution in main() I a...

How to automatically run in the background?

I'm not sure that it's not implemented yet, I hope that it is. But I know that in .Net programmers should manually run time-consuming task in the background thread. So every time we handle some UI event and we understand that this will take some time we also understand that this will hang UI thread and our application. And then we make ...

Windows.Forms.Timer instance and UI threads

I have a custom control whose primary purpose is to draw data. I want to add a ScheduleUpdate(int milliSeconds) method to the control which will force an update X milliseconds from now. Since this is all GUI land, I should be using a Windows.Forms.Timer, but how does this timer instance know which thread it belongs to? What if Schedule...

C++ boost thread id and Singleton

hi. Sorry to flood so many questions this week. I assume thread index returned by thread.get_id is implementation specific. In case of the pthreads, is index reused? IE, if thread 0 runs and joins, is thread launched afterwords going to have a different ID? the reason I ask this is a need to implement Singleton pattern with a twist: ...

Multiple file descriptors to the same file, C

I have a multithreaded application that is opening and reading the same file (not writing). I am opening a different file descriptor for each thread (but they all point to the same file). Each thread then reads the file and may close it and open it again if EOF is reached. Is this ok? If I perform fclose() on a file descriptor does it af...

Spawning BackgroundWorkers

We have a business case that would be perfect for multiple BackgroundWorkers. As an example, we have a form with a "Save" button on it. Normally we would run all the save commands (Save is an example) synchronously and then close the form. We would like to now split the work onto separate threads using backgroundworker. We will loop th...

Socket server with multiple clients, sending messages to many clients without hurting liveliness

I have a small socket server, and I need to distribute various messages from client-to-client depending on different conditionals. However I think I have a small problem with livelyness in my current code, and is there anything wrong in my approach: public class CuClient extends Thread { Socket socket = null; ObjectOutputStream out; ...

Using Java Executor on AppEngine causes AccessControlException

How do you get java.util.concurrent.Executor or CompletionService to work on Google AppEngine? The classes are all officially white-listed, but I get a runtime security error when trying to submit asynchronous tasks. Code: // uses the async API but this factory makes it so that tasks really // happen sequentially Executor ...

WPF - Dispatcher PushFrame()

Hello, I'm trying to call Dispatcher.PushFrame() from several different thread but encounter an error: Must create DependencySource on same Thread as the DependencyObject. Here is a code snippet: _lockFrame = new DispatcherFrame(true); Dispatcher.PushFrame(_lockFrame); When I tried: Dispatcher.CurrentDispatcher.Invoke( D...

Explicit call of Runnable.run

Hi, I have a question. Somebody, who was working on my code before me, created some method and passed Runnable as parameter, more likely: void myMethod(Runnable runnable){ runnable.run(); } Then calling myMethod out of main looks like: public static void main(String args[]) { try { myMethod(new Runnable(){ public void run() { //do...

Thread loses Message after wait() and notify()

Hey Guys! I have a problem handling messages in a Thread. My run-method looks like this public void run() { Looper.prepareLooper(); parserHandler = new Handler { public void handleMessage(Message msg) { Log.i("","id from message: "+msg.getData.getString("id")); // handle message this....

How to tell when my batch of EAP calls are completed?

This is following my question: http://stackoverflow.com/questions/2607038/c-how-to-consume-web-service-adheres-to-the-event-based-asynchronous-pattern My program is calling the DoStuffAsync() x many times in a batch, hence the callback will get invoked the same number of times upon OnComplete(). Is there a way to find out when my batch...

How to suspend a running thread using win32 api's?

Here it is Create a thread in suspended state. hThrd1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) ThreadProc1, (LPVOID) &obj1, CREATE_SUSPENDED, &dwFirstThreadID); Resume the thread whenever required ResumeThread(hThrd1); How do I suspend this running thread. I may resume it after sometime, but I want to suspend it now. I c...

java -> System.gc(); Does this call opens a new Thread or not?

For example I such a code ... get some memory and lose all the pointers to that memory so that System.gc(); can collect it. call System.gc(); do some other tasks; Here does the "do some other tasks;" and "System.gc();" works in paralel or does the "do some other tasks;" waits for "System.gc();" to be executed Thank you ...

Java GUI, need to pause a method without freezing GUI aswell

I know that this problem is caused by the sleep or wait calling on the main thread and that the answer on how to solve this will be to put the method into a seperate thread and then make that thread sleep. But the code is a mess and don't really have the time to sort it out and split it up into separate threads and was wondering if there...

Multithreading, when to yield versus sleep

hello. To clarify terminology, yield is when thread gives up its time slice. My platform of interest is POSIX threads, but I think question is general. Suppose I have consumer/producer pattern. If I want to throttle either consumer or producer, which is better to use, sleep or yield? I am mostly interested in efficiency of using eith...

Pattern for iPhone background loading during init?

Hi everyone, I'm currently kicking off a background thread to do some REST queries in my app delegate's didFinishLaunchingWithOptions. This thread creates some objects and populates the model as the rest of the app continues to load (because I don't block, and didFinishLaunchingWithOptions returns YES). I also put up a loading UIViewC...

Testing a Non-blocking Queue

I've ported the non-blocking queue psuedocode here to C#. The code below is meant as a near verbatim copy of the paper. What approach would you take to test the implementation? Note: I'm running in VS2010 so I don't have CHESS support yet. Edit: I've removed the code in question so some unsuspecting developer doesn't use it -- it req...

C++ standard thread class?

I have come across many ad hoc implementations of thread class in C++, but why is there no standard library thread class like the one in Java? The one that I generally use in C++ is http://www.linuxdocs.org/HOWTOs/C++Programming-HOWTO-24.html ...