21
votes
3answers
2k views

What are the best practices with multithreading in C#?

For a while I have been interested in seeing if some tasks work well when split across multiple threads. On the one project I have been busy with I have been creating a lot of small utility apps, to ...
2
votes
1answer
3k views

Polling loop to run in a background thread

I came up with the idea of a small utility class that will poll some delegate until the response received meets some condition, upon which it will notify the main thread which can take the appropriate ...
5
votes
1answer
1k views

The correct (and safe) way to use a Timer to poll a Delegate

This is a followup to Polling loop to run in a background thread where I was initially using a single thread and Thread.Sleep() to poll a delegate. I was ...
4
votes
1answer
770 views

Thread-safe wrapper around WCF ServiceModel.ClientBase subclass

I have an ASP.NET application which uses a Service Reference to a (third-party, offsite) payment processor. The service reference class is generated automatically. Its implementation is a subclass of ...
4
votes
2answers
365 views

UNC path exists monitor

This is my first attempt at trying to write a "monitor" class to determine if a UNC path is available. I need the monitor to not block the main thread and to also event when the UNC is toggled UP/DOWN ...
9
votes
4answers
638 views

Clean and well-designed Tic-Tac-Toe game

My design goal was to try and make a "clean" and well-designed Tic-Tac-Toe game but also to try and use concepts and programming constructs that I'm new to. I'm planning to implement an "AI Player" ...
4
votes
2answers
139 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 ...
4
votes
2answers
1k views

Using a recurring System.Threading.Timer in an Mvc Application

I'd like your opinion on something. I have the following class: ...
2
votes
4answers
3k views

Designing a better logger class

Could you please critisize the logger class below? Can it be used in a multi threaded web environment? If not how can I improve it? Is there anything wrong with locking in WriteToLog method or ...
1
vote
3answers
78 views

How to correctly get a IDisposeable when you need to lock the factory?

If I need to create a IDisposeable object from a factory, but if the factory object is not thread safe and requires me to lock on it is this the correct pattern to use? ...