multithreading

C# Real benefit of Threadpooling

I am trying to optimize the code for an application we are currently developping. The current implementation invovles creating a thread to continously poll a server for new data. If new data is found the thread then spawns multiple threads (created every time) to retrieve the data. I was reading regarding thread pooling and was curious ...

Can you rethrow a c# exception on a different thread?

Is it legal and safe in C# to catch an exception on one thread, and then re-throw it on another. E.g. is this legal Exception localEx = null; Thread mythread = new Thread() { () => { try { DoSomeStuff(); } ...

Threaded Django task doesn't automatically handle transactions or db connections?

I've got Django set up to run some recurring tasks in their own threads, and I noticed that they were always leaving behind unfinished database connection processes (pgsql "Idle In Transaction"). I looked through the Postgres logs and found that the transactions weren't being completed (no ROLLBACK). I tried using the various transactio...

How accurate is Thread.Sleep(TimeSpan)?

I've come across a unit test that is failing intermittently because the time elapsed isn't what I expect it to be. An example of what this test looks like is: Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); TimeSpan oneSecond = new TimeSpan(0, 0, 1); for(int i=0; i<3; i++) { Thread.Sleep(oneSecond); } stopwatch.Stop();...

How do I speed up my Ruby application?

I am making a data intensive web application that I am trying to optimize. I've heard of forking and threading, but I have no idea whether they are applicable to what I am trying to do and if so how to implement them. My code looks like this: def search @amazon_data=Hash.from_xml(item.retrieve_amazon(params[:sku])) unles...

Cleaning up static references

Hi, I have static class with static dictionary with some informations. The dictionary has key as WeakReference (i don't want prevent garbage collection of the real key object ). Code sample: public static class ThreadHelper { private static readonly object syncRoot = new object(); private static Dictionary<WeakReference, Thread...

Event for unhandled exceptions in Silverlight background threads?

Is there a usable equivalent of AppDomain.UnhandledException for Silverlight? I say usable, because, although the method exists in Silverlight, MSDN has it marked as SecurityCritical. What I'd like is to receive notification of Exceptions happening on background or ThreadPool threads so that I can log them. Application.UnhandledExceptio...

Overhead due to use of Events

I have a custom thread pool class, that creates some threads that each wait on their own event (signal). When a new job is added to the thread pool, it wakes the first free thread so that it executes the job. The problem is the following : I have around 1000 loops of each around 10'000 iterations do to. These loops must be executed sequ...

Are .NET modules thread safe?

I have a .NET module that I need to call from an instantiated class. Can I count on only one object at a time being able to access the functions in a module (something like instantiating a module) or will I need to look at locking within the class? I can't seem to get a clear answer to this anywhere. Thanks! ...

Python question regarding a server listener

I wrote a plug-in for the jetbrains tool teamcity. It is pretty much just a server listener that listens for a build being triggered and outputs some text files with information about different builds like what triggered it, how many changes there where ect ect. After I finished that I wrote a python script that could input info into tea...

PLINQ problem / techniques to impliment multi-threaded, lock-free lists (in C#).

Here's the code in question: parentNodes.AsParallel().ForAll(parent => { List<Piece> plist = parent.Field.GetValidOrientations(pieceQueue[parent.Level]); plist.ForEach(p => { TreeNode child = new TreeNode(p, parent); var sco...

How to create a thread in WinForms?

I need help in creating a thread, C# winforms private void button1_Click(object sender, EventArgs e) { Thread t=new Thread(new ThreadStart(Start)).Start(); } public void Start() { MessageBox.Show("Thread Running"); } I keep getting this message: Cannot implicitly convert type 'void' to 'System.Threading.Thread what to do...

Get call stack from any thread within C.

In C on Solaris 10, I'd like to get the call stack from an arbitrary thread within a process. I have many worker threads and one thread which monitors them all to detect tight loops and deadlocks. The function I'd like to implement is for the monitoring thread to print the call stack from the "hung" thread several times before it kills...

C# thread functions

Can i make any function like public void myfunc() { //some processing } a thread function by Thread t = new Thread (new ThreadStart (myfunc)); then some where t.Start(); and can i pass any type of arguments to that? ...

Code Reuse , Threading Class

C# What type of winforms or controls implement "Invoke/BeginInvoke" functions ...

MethodInfo.Invoke sometimes returns null and sometimes returns value

Hi all, I'm working on an asp.net MVC application. I have a class that wraps a repository that fetches data from a db using simple linq statement. I've written a decorator class to add caching logic (using caching application block). since I have several methods that I want to decorate, and the logic is all the same for each one (chec...

Multithreading TeeChart & Media Element

Hi, I am working in WPF, using a Media Element and a WPF TeeChart (by Steema). Both of these are visible and updating at the same time - whilst the video is playing, the graph will update at regular intervals to show data relevant to the current location in the video. The problem is that the TeeChart takes a long time to update, which ...

C# Threads - Parent Access Problem

my aim is that in the function "Dummy" i can change the controls like labels etc of the form from which the thread is initiating..how to do it..please don't suggest completely different strategies or making a worker class etc...modify this if you can Thread pt= new Thread(new ParameterizedThreadStart(Dummy2)); private...

What is the Re-entrant lock and concept in general?

I am always get confused . Would someone example what Reentrant means in different contexts? And why would you want to use reentrant vs. non-reentrant. Say pthread (posix) locking primitives, are the re-entrant or not? What pitfalls should be avoided when using them Is mutex re-entrant? Thanks ...

Using a global dictionary with threads in Python

Is accessing/changing dictionary values thread-safe? I have a global dictionary foo and multiple threads with ids id1, id2, ... , idn. Is it OK to access and change foo's values without allocating a lock for it if it's known that each thread will only work with its id-related value, say thread with id1 will only work with foo[id1]? ...