Archive for 'C#' Category
Exceptions in BackgroundWorker
To save 15 minutes of confusion.
If an exception is thrown in a BackgroundWorker’s DoWork handler, the backgroundworker will catch it and place the exception in RunWorkerCompleted’s e.Error.
If it seems like the Exception’s still being thrown with no apparent way to catch it, it’s becauseĀ if e.Error is not null. When that’s the case, e.Result will throw [...]
Initializing DataRows
How many ways are there to initialize a new DataRow with new values?
Set the DefaultValue property on the respective DataColumns.
This works fine for static values. However, you’re likely using the DataSet designer in Visual Studio, and it will hose itself if you try to set a GUID because it can’t tell them apart from a [...]
C# events are actually accessors
An interesting feature of C# I discovered recently is that events are actually accessors into Multicast Delegates, much like properties are accessors into other fields.
private string myData;
public string MyData // A property
{
get { return myData; } // called when the property is read
set { myData = value; } // called when [...]
How to get a (non-visual) ComponentModel.Component’s parent Form or Control
I recently ran into the need to get the reference of the parent form of a Component that I was creating. The problem is that Components, unlike Controls, don’t have a Parent property, nor any other simple way of getting it. I’ve browsed around for solutions, but I could only find vague references to what [...]