multithreading

Why am I getting this error:"Cross-thread operation not valid: Control lbFolders accessed from a thread other than the thread it was created on."?

This is baffling me, maybe somebody can shine the light of education on my ignorance. This is in a C# windows app. I am accessing the contents of a listbox from a thread. When I try to access it like thisprgAll.Maximum = lbFolders.SelectedItems.Count; I get the error. However, here is the part I don't get. If I comment out that line...

Tell if 'elapsed' event thread is still running?

Given a System.Timers.Timer, is there a way from the main thread to tell if the worker thread running the elapsed event code is still running? In other words, how can one make sure the code running in the worker thread is not currently running before stopping the timer or the main app/service thread the timer is running in? Is this a m...

Stopping a Thread in Java?

I'm in the process of writing a piece of code that connects to a server spawns a bunch of threads using that connection and does a bunch of "stuff". There are certain instances where the connection fails and I need to stop everything and start from scratch with a new object. I wanted to clean up after the object but calling thread.stop...

java thread question

I have some thread-related questions , assuming the following code (please ignore the possible inefficiency of the code,I'm only interested in the thread part): //code without thread use public static int getNextPrime(int from) { int nextPrime = from+1; boolean superPrime = false; while(!superPrime) { boolean prime = t...

-[NSOperationQueue operations] returns an empty array when it shouldn't?

I'm writing an application that does async loading of images onto the screen. I have it set up to be NOT concurrent (that is, it spawns a thread and executes them one at a time), so I've only overridden the [NSOperation main] function in my NSOperation subclass. Anyway, so when I add all of these operations, I want to be able later to ...

NSThread with _NSAutoreleaseNoPool error

I have an method which save files to the internet, it works but just slow. Then I'd like to make the user interface more smooth, so I create an NSThread to handle the slow task. I am seeing a list of errors like: _NSAutoreleaseNoPool(): Object 0x18a140 of class NSCFString autoreleased with no pool in place - just leaking Without NST...

Single-threading two processes

I have two C++ processes (A and B), executing under Windows, where one launches the other. I would like to effectively single-thread their execution. For example: Start process A A creates B A suspends B executes some fixed set of operations B suspends and A is resumed A executes some fixed set of operations A suspends and B is resumed...

using system.thread.threadpool in powershell

Hi all, I am after a example of some code in powershell using the threadpool. my friends at google can not help me. Any example would be great. Donald ...

Synchronising twice on the same object?

I was wondering if in Java I would get any odd behaviour if I synchronise twice on the same object? The scenario is as follows pulbic class SillyClassName { object moo; ... public void method1(){ synchronized(moo) { .... method2(); .... } } public void me...

C# 2.0 Threading Question (anonymous methods)

I have a simple application with the following code: FileInfo[] files = (new DirectoryInfo(initialDirectory)).GetFiles(); List<Thread> threads = new List<Thread>(files.Length); foreach (FileInfo f in files) { Thread t = new Thread(delegate() { Console.WriteLine(f.FullName); }); thread...

Why is lock(this) {...} bad?

The MSDN documentation says that public class SomeObject { public void SomeOperation() { lock(this) { //Access instance variables } } } is "is a problem if the instance can be accessed publicly". I'm wondering why? Is it because the lock will be held longer than necessary? Or is there some more insidious reason...

Timing a line of code accurately in a threaded application, C#

Hi, What is the most accurate way of timing a thread or a line of code in C# assuming the application is multithreaded? Kind regards, ...

What is the correct way to deal with procedures that take a "long time" to complete?

I have a Winforms application created in Visual Studio 2005 Pro, it connects to an SQL Server 2005 database using the SqlConnection / SqlCommand / SqlDataAdapter classes to extract data. I have stored procedures in my database to return the data to me. What is the best way to handle queries that take a "long time" to complete? (i.e long...

Will setting the only reference to null mean it and its child threads are garbage collected?

I have an application which has to live as a service, I create an object which then spawns off a buch of threads. If I set the only reference to that object to null will all the child threads get cleaned up? or will I suffer from a memory leak. Do I have to explicitly terminate all the child threads? ...

Multi-Parameterized Threads Efficiency

Would there a more elegant way of writing the following syntax? Thread t0 = new Thread(new ParameterizedThreadStart(doWork)); t0.Start('someVal'); t0.Join(); Thread t1 = new Thread(new ParameterizedThreadStart(doWork)); t1.Start('someDiffVal'); t1.Join(); Presuming we want to pass 20 d...

How to stop long executing threads gracefully?

I have a threading problem with Delphi. I guess this is common in other languages too. I have a long process which I do in a thread, that fills a list in main window. But if some parameters change in the mean time, then I should stop current executing thread and start from the beginning. Delphi suggests terminating a thread by setting Te...

How much memory does a thread consume when first created?

I understand that creating too many threads in an application isn't being what you might call a "good neighbour" to other running processes, since cpu and memory resources are consumed even if these threads are in an efficient sleeping state. What I'm interested in is this: How much memory (win32 platform) is being consumed by a sleepin...

Best programming approach/methodology to assure thread safety

When I was learning Java coming from a background of some 20 years of procedural programming with basic, Pascal, COBOL and C, I thought at the time that the hardest thing about it was wrapping my head around the OOP jargon and concepts. Now with about 8 years of solid Java under my belt, I have come to the conclusion that the single har...

Can I monitor the size of a thread's message queue?

Our application is getting a System Call Failed RPC error from DCOM (0x80010100), we suspect that the target thread's message queue is full (although I'm not convinced this is ture). I know the queue is limited to 10,000 messages and I want to see if we're close to this number in the common cases. Is there a way to monitor the size of a ...

How to change the priority of a thread in run time in windows?

I am writing a multi-thread application in windows OS. All threads are runing as services. If I want to change the priority of service in run time, how can I do this? Does windows provide any API? Many Thanks! ...