Managing multiple threads in C# with a GUI
Objective: manage multiple threads from C# with a responsive GUI
Description:: In this example, I simulate encoding from a source that is splittable in segments. It could be the b-frames between I-frames in a video or even some sort of audio codec. To simulate the workload, I use Thread.Sleep(TimeInMs).
For this code, I have 4 threads working on a source to encode of 10 segments. Each threads will take a slice to encode, process it and reassemble the end result in an array, that can be utilized by another process to unify the encoded version, for example.
A word of caution though: although working with threads can be useful in some cases it also complicates the code quite a bit, especially at debugging. It’s much harder to keep track of what is going on.
Here is the code in the windows form (download the whole project in VS2008 at the end):
C# Crash report – How to handle remote crash report with HTTP POST
Objective: Make your applications report any unhandled crash to a database on a remote server.
Description:You have a Reporter class that will send the values to page accepting POST data. The application main entry point will be surrounded by a Try Catch block (effectively catching every possible unhandled errors in the application). It will then try to send the stack trace of the error to the webpage. If it can’t (ie. no internet connection, server down) it won’t do anything and the application quits.
It can be very useful to catch those bugs you didn’t see or thought possible without mass testing and QA…which, let’s face it, you can’t afford as a self programmer. Your users are your testers! ![]()
A word of caution though, you might want to warn your users you’re sending data, and what kind of data you’re sending before using this. In this example, it doesn’t warn the end user.
On to the code below the break!



