multithreading

C#/.NET: Testing BackgroundWorker with NUnit

This test fails when it is run with the NUnit console runner. It works if I run just that test with TestDriven.NET, but not if I run the entire suite with TestDriven.NET: [Test] public void BackgroundWorkerFiresRunWorkerCompleted() { var runner = new BackgroundWorker(); ManualResetEvent done = new ManualResetEvent(false); runner.R...

Why does my collection decide to start at 0 instead of 1?

I'm having a problem where a collection of objects isn't being accessed correctly when run on a thread from a service. I can run my unit tests fine in VS2008 but when I attach the debugger to the service i can clearly see that it's not starting at the 1 based index but instead at the 0 based index. I've tried everything that I can thin...

Accessing objects in different controllers while using different threads in cocoa

Hi, I'm pulling in xml using the cocoa NSXmlParser. Since this process most likely won't finish before my view is loaded I want to move it to a secondary thread like I have seen in many examples including the seismicxml example on the apple site. The flow of my application is as follows. I have a table view which cells can be clicked t...

Does lock(){} lock a resource, or does it lock a piece of code?

I'm still confused... When we write some thing like this: Object o = new Object(); var resource = new Dictionary<int , SomeclassReference>(); ...and have two blocks of code that lock o while accessing resource... //Code one lock(o) { // read from resource } //Code two lock(o) { // write to resource } Now, if i have two thr...

How to catch exceptions from a ThreadPool.QueueUserWorkItem?

I have the following code that throws an exception: ThreadPool.QueueUserWorkItem(state => action()); When the action throws an exception, my program crashes. What is the best practice for handling this situation? Related: Exceptions on .Net ThreadPool Threads ...

Passing variables to the Event Dispatch Thread

Hello, my GUI locks up because I need to update it through the EDT, however, I need to also pass a variable that is being updates with the GUI: while ((message = this.in.readLine()).startsWith("NUMPLAYERS")) { numOfPlayers = Integer.parseInt(message.split(":")[1]); numPlayers.setText("There are currently " + numOfPlayers + " pla...

Ensuring thread synchronization in SQL possible?

If I have several SPs SP1 SP2 some_inline_queries how do I ensure that they are all run at once without interruption from other threads? Is it possible to do this from SQL Server level? edit: Let's say we have a main script with 3 major actions: sp1 scans table t1 to generate a random string that is unique to column c1 in t1; s...

Communication between the EDT and main threads in JAVA

Hello, I have been asking a lot of questions about a project I have been working on recently. Here is the scenario I am in and any help or point in the right direction would help a lot... This is a network program built with a server and multiple clients. Each client has a GUI which must act according to commands sent from the server. ...

C++ Random Seed, Global Objects, and SDL_Threads

In my program, I have an object the global cpp file, that takes an integer as an argument. //In global header extern Object example; //In global cpp file Object example( (rand() % 6) ); I want a random number to be generated to the object's argument, but the seed does not reach the global variable, as the seed created in another cpp ...

What is the exitContext used for on a WaitHandle.WaitOne method.

Example System.Threading.AutoResetEvent e = new System.Threading.AutoResetEvent(false); bool b = e.WaitOne(1000, false); I've done a lot of multi threaded development in my time and have always wondered what the use of the that method was for. The second boolean parameter on the WaitOne is called exitContext. MS Help states "t...

Is there any way to stop an application shutting down with work still in the system Threadpool

Final question for today :) thanks for your input on the previous ones. BTW: Already searched the forum on this and nothing quite answers this one. We use some 3rd party libraries which pop work onto the Threadpool and we don't want to shutdown while there are outstanding activities. When shutting down an application, the application w...

Memory usage in C#

I have a program that uses threads in C#. Is there a way to know programmatically the memory usage of the application? I want to limit the spawning of threads to say 10 megabytes of memory, how would I do that? ...

Claim resources/memory from thread single threaded apartment thread

I am using following single threaded appartment. I am unable to reclaim memory/other resources from thread object. Actullay I want to wrap my thread in try catch and fianlly block. try and catch are done. But I am unsure about finally block. What code, property or function do I need to call in finally block. System.Threading.Thread myTh...

A question on IOCP

If I want to use completion port to get information from different thread , how can I design the structure of the program?How about the one below? If I want to use a global function ,how can I set the mutexes ? Main(){ for i in range NumOfThreads{ CreateIoCompletionPort() CreatThread(ThreadFun) } } ThreadFun(){ Whil...

I'm concerned this code isn't doing what I want it to because of the way objects are used.

I have the following code and I was wondering if someone could look at it for me. I have a multi-threaded application that all share an object and operate on it. I've created a pointer to a certain element of it, just so I don't have to type in the long path every time, but I'm concerned it might simply be modifying a copy of the share...

How to switch between primary and secondary thread within different controllers in cocoa

Hi, I know I can create a separate thread in cocoa touch with the following code: [NSThread detachNewThreadSelector:@selector(getEarthquakeData) toTarget:self withObject:nil]; How to go back to the process of my primary thread? I know I can do this from the delegate with this code: [(id)[[UIApplication sharedApplication] ...

How to understand asynchronous io in Windows?

1.How to understand asynchronous io in Windows?? 2.If I write/read something to the file using asynchronous io : WriteFile(); ReadFile(); WriteFile(); How many threads does the OS generate to accomplish these task? Do the 3 task run simultaneously and in multi-threading way or run one after another just with different order? 3.Ca...

Investigating python process to see what's eating CPU

I have a python process (Pylons webapp) that is constantly using 10-30% of CPU. I'll improve/tune logging to get some insight of what's going on, but until then, are there any tools/techniques that allow to see what python process is doing, how many and how busy threads it has etc? Update: configured access log which shows that there ...

When should each thread synchronization objects be used?

Under what circumstances should each of the following synchronization objects be used? ReaderWriter lock Semaphore Mutex ...

UIACtionSheet Delegate Question

I am using an action sheet to alert a user to several items upon logging into my app. listed are some examples of the alerts and the buttons that go with them. INVALID USER - OK INVALID PASSWORD - OK INVALID USER - OK UNKNOWN USER - CREATE NEW USER, CANCEL USER ALREADY LOGGED IN - DISCONNECT, CANCEL LOGIN What is the best way to manag...