10
votes
7answers
7k views

A custom thread-pool/queue class.

I wanted a class which executes any number of tasks but only a certain amount at the same time (e.g. to download various internet content and keep the overall download speed at a good level). The ...
8
votes
4answers
429 views

Code works but memory usage is erratic

I have the following class which is a tool for retrieving MD5 hashes of files that are input into it. They can potentially be very large files and I require cancellation and progress report, hence why ...
5
votes
4answers
215 views

Should a piece of code only ever called once be a separate method?

I'm curious when a piece of code should be its own method or just left alone. This came up when I was creating a "work item" from the thread pool. When passing the argument to the "WaitCallback" ...
5
votes
1answer
2k views

Polling loop - Always a bad decision?

I had a need to isolate some long-running blocking calls in a background thread of my app. I also needed to keep this thread running indefinitely, because COM would complain if some object I created ...
5
votes
1answer
2k views

C# multi-thread ping

Hey guys, I'm working on a netmork monitoring application, that pings a (not known) number of hosts. So far I have the code below. I've made a class PingHost with a function zping and I called it with ...
5
votes
1answer
897 views

Refactoring a multi-threaded producer-consumer model

This is an architecture question for a multi-threaded program which is going to be moved from C# .NET 2 to .NET 4. The program currently has multiple processing threads, and one database I/O thread. ...
5
votes
2answers
235 views

How can I make this fast and more readable?

I made a simple library to help me doing A/B tests in a web app. The idea is simple: I have two or more page options (url) for a given page and every call to the library method should give me a url so ...
5
votes
4answers
560 views

Associating a lock/mutex with the data it protects

I've recently come across some areas of code in our solution that have a few thread-safety problems. Thread-safety is a minefield at best so I thought I'd have an attempt at writing a few little ...
4
votes
4answers
1k views

Action queue in .NET 3.5

Because I needed to execute some actions one by one in seperate thread (not to block GUI) and I couldn't use Task.ContinueWith from .NET 4.0 I decided to write it by myself. Here is how it evolved ...
4
votes
2answers
114 views

Getting a decryptor object

I need to lock on my AesManaged instance _Aes to call CreateDecryptor() however the CreateDecryptor() method is not thread safe and this function could be called by multiple threads. Is this the ...
4
votes
6answers
383 views

Strategy for avoiding threadpool starvation while performing cpu bound jobs in a queued fashion

My aim is to avoid using threadpool threads for CPU bound work, thus avoiding a situation where IIS stops responding to new requests. Can you see any problems with the code below? Is this a ...
4
votes
1answer
179 views

Is this custom dictionary thread-safe?

I'm writing a custom dictionary which is to be used as a helper for caching. The reason I use delegates is because it must interface with generated code, so I can't change this. However, you can ...
4
votes
2answers
259 views

Returning a large number of values from a thread in c#

I have an application in which I am querying an XML web service continuously every 2 seconds in a thread. The returned XML is very big and I am retrieving lots of stuff from them using XPath and ...
4
votes
2answers
558 views

Threadsafe DBContext in singleton

I found out the hardway that access to DbContext in .NET is not threadsafe. I have a singleton for logging things using a dbcontext. The original version uses something like public Logger{ private ...
4
votes
2answers
4k views

C# Asynchronous Sockets: Is this thread-safe and correctly done?

I need to implement a TCP client application. The client and the server send messages to each other. I want to make this program scalable enough to handle connections to multiple servers at the same ...

1 2 3 4 5
15 30 50 per page