multithreading

Thread Crossing in Windows Forms Application

Hi, I have used two threads in my application(WindowsForms). The one thread for getting ThumbnailImages of clients and another thread for getting fullsize Images of Clients...its working but not properly... When i click thumbnail image button its giving thumbnail image properly after that i click that fullsize image button,It came as fu...

Time-limited computation in Ruby

I want to run a task in Ruby for up to (say) 10 seconds, and kill that task if it has taken longer. This is to prevent hanging of an external process. What's the best way of implementing this? In particular, how would I write the function for_up_to_10_seconds below? loop do for_up_to_10_seconds do # something end end ...

Is this code threadsafe or why am I concern with Url.Helper

Say that I have public static class M { public static string Concat(string a, string b) { return N.AddOne(a, b); } public static string Concat2(string a, string b) { return SomeThreadSafeMethod(a, b); } } public static class N { public static string AddOne(string a, string b) { retur...

reassign thread to a different method vb.net

Is it possible to reassign thread to a different method, once it has been instantiated. If not, are there alternatives? ...

.NET ParameterizedThreadStart wrong return type

Hello, I just started experimenting with Threads and I ran in to a problem I'm not able to solve on my own. I get the error: Error 1 'bool projekt.ftp.UploadFil (object)' has the wrong return type I use this code to start a thread using the method ftp.Uploadfile: Thread ftpUploadFile = new Thread(new ParameterizedThreadStart(ftp.Upl...

Simulating Java's Thread.sleep() in WM

Is there an easy way to make some "sleeping program" functionality by just calling function, such as it has been made in Java with Thread.sleep()? Sleep method causes, in brief, app to wait indicated time (no. of milisec.) and after that time returns to next line of code (so it "blocks" - it isn't not proper word, though - the current t...

pthread with callback to python VM

Let's say I have a python script which loads a shared library (SL) through ctypes. The SL sets up a pthread T1 The python script configures callbacks through the SL i.e. python script calls functions from the SL with references to python callables Now, let's say T1 calls a "callback" function, are the following assumptions true: ...

How should I handle exceptions that are thrown during asynchronous methods that I've made syncrhonous? (or, Is this a code smell?)

I'm writing a synchronous method that calls an asynchronous method on another server. The server's method calls a callback when it's done, and in case of error one of the callback's arguments contains an exception. I'd like to throw an exception from my method, with the server's exception as its InnerException. However, in order to ca...

How to timeout a thread

I want to run a thread for some fixed amount of time. If it is not completed within that time, I want to either kill it, throw some exception, or handle it in some way. How can it be done? One way of doing it as I figured out from this thread is to use a TimerTask inside the run() method of the Thread. Are there any better solutions fo...

how to close a java frame with threads

I have a java frame that I want to close it automatically after 3 or 4 seconds. I found out I must used threads. but I dont know how exactly to do it, this a dumy part of my code : package intro; import java.awt.*; import java.io.IOException; //import view.LangMenu; public class IntroClass extends Frame { private int _screenWidth...

Java RMI and Thread Synchronization questions

Hello Stack Overflow! I actually have two questions about Java RMI and thread synchronization: 1) If I implement my RMI remote methods as synchronized, are they guaranteed to be mutually exclusive? I need to make sure that no two of my RMI methods (methods offered to clients) execute at the same time. 2) I have a method that the serve...

C# delegates, reference resolution time.

Hi, I have a simple question about .net delegates. Say I have something like this: public void Invoke(Action<T> action) { Invoke(() => action(this.Value)); } public void Invoke(Action action) { m_TaskQueue.Enqueue(action); } The first function encloses a reference to this.Value. During runtime,...

After casting pParam, why do I get random characters back?

Hi! This is the first time that i want to use threads, so i don't understand them fully for now. I have two structures: struct ddata //difference content { char *filename; char *size; }; struct ddata *difference = (struct ddata *) malloc( dif * sizeof *difference ); struct test { struct ddata* difference; int diff; ...

Android: running a thread in background

Hi, is there any way to leave a thread in background when i close the app in android? I read about a Service but implementing it is too much than i need. Thanks ...

Problem with using Semaphore to protect queue

I am using following code to limit use of resources. Once in a while(after 3-4 days of successful run) I get queue empty exception or the returned object is found to be null. I am wondering if I am limiting only 5 threads to enter this Get method, how come this happens. The places where GetConnection is called, ReleaseConnection is al...

What's wrong with this Objective-C threading code for my iPhone app?

This piece of code: - (IBAction) getXML { goButton.enabled = NO; [self performSelectorInBackground:@selector(parseInBackground) withObject:nil]; } - (void)parseInBackground { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; xmlParser = [[XMLParser alloc] init]; NSURL *xmlurl = [[NSURL alloc] initWithStrin...

Difference between Re-entrant and Thread-Safe function

What is the difference between a re-entrant function and a thread safe function? ...

What should I do on exceptions thrown by SwingUtilities.invokeAndWait

SwingUtilities.invokeAndWait() throws an InterruptedException and an InvocationTargetException how should I handle these? public static void invokeAndWait(Runnable doRun) throws InterruptedException, InvocationTargetException I want to use the method to show a dialog and wait for the user to say yes o...

Reset a CoreData persistent store

Hi everybody, Basically, what I'm trying to do is to wipe out all data in my CoreData persistent store, then import new data. How would you do this? It seems that the simplest solution is call [NSPersistentStoreCoordinator removePersistentStore:error:] and then remove the file. Is that the best practice available? Is it thread-safe? Th...

WPF: Is there a simple way to create a Progress Window?

I tried creating one, but the BackgroundWorker in Window1 couldn't access the ProgressBar in Window2 once the reportProgress was activated, because "The calling thread cannot access this object because a different thread owns it". Seems there's a lower level thread model I could use, but it also seems a lot more complicated. ...