Great Primer for Threading Basics in .Net

I stumbled across this article from one of my LinkedIn friends,  Threads in C#

It answered one of my questions about thread pooling in a very concise, easy to understand fashion.  It is a short article, but he then goes into the Task Parallel Library, something that I really enjoy.

If you are asking why should I care about this, I use the magic of Async/Await.  These are the fundamental technologies and techniques that they are built upon.

Keep in mind that not many people are experts in highly concurrent systems, I am not one of them either.  But hopefully by reading this article we will all be a little better in how we implement parallelism/concurrency.

Cheers!

DataGridView, FormattingException, DataError, and PreferredSize ~ Auto-Sizing Issue

Alright so I think I now have a good handle on this now. If you are using auto sizing for your columns, you might run into a formatting exception. The error you get says that you can handle the error in the DataError event.

If you start error handling within that event you might notice that you get a context of 5 which says it is either a Formatting or PreferredSize data error context. To quote MSDN:

A data error occurred when calculating the preferred size of a cell. This value indicates that the DataGridView failed to calculate the preferred width or height of a cell when programmatically resizing a column or row. This can occur if the cell failed to format its value.

Cancel the event by issuing the following e.Cancel = True after checking to make sure that the DataGridViewDataErrorEventArgs (e) has the context of 5 for PreferredSize

SQL Server Reporting Services ~ Cascading/Dependant Parameters

This is my first screencast, enjoy!

Visual Basic Basics: Visual Basic 2010 – Implicit Line Continuation

VB Line Continuation Operator (_ underscore)

Yay _

no more _

under scores _

for line continuation!!!!!_

It was one of my pain points in VB. Please visit the below, he does a wonderful job explaining it.

Visual Basic 2010 : Implicit Line Continuation – Fryan’s Digital World.

And of course, we all know that Visual Basic is superior to C#:

http://www.simple-talk.com/dotnet/.net-framework/10-reasons-why-visual-basic-is-better-than-c/

Honestly I like both, but I am partial to VB, C# is a little more masochistic.

DirectoryOperationException – The object does not exist.

System.DirectoryService.Protocols Library

This was a very frustrating error. I was able to connect to LDAP through LDAPadmin but not through a program I was creating. “The object does not exist” error occurs, at least in my experience when the credentials you are passing to the server do not authenticate.

In this case I was getting nowhere. Resorting to Wireshark, filtering against port 389, which is the port for LDAP resulted in me seeing a backslash in the credentials being passed as well as the username coming after the organization, which is wrong for my environment.

The resolution was to set the domain to nothing in VB or null in C# in my Net.NetworkCredential object. At the same time moving the organization to the username property.

Dim credLDAP As New Net.NetworkCredential(“cn=username”,”password”, “o=domain”)
does not work, but this does:
Dim credLDAP As New Net.NetworkCredential(“cn=username,o=domain”,”password”, nothing)

Visual Studio – Data Binding: “The operation could not be completed. Access denied.”

I ran into this problem yesterday and let it go until this morning. I got this error message and had a hard time figuring it out.  Here is a link to the MSDN Forum thread discussing this: http://social.msdn.microsoft.com/forums/en-US/vblanguage/thread/94868d04-de4f-44a9-a362-4ffb1f130bae

This particular thread is specific to Visual Studio Express but is really applicable to all editions of Visual Studio 2005.

The Solution

Open your project’s properties tab.

In the Debug section uncheck “Enable the Visual Studio hosting process”.

This will allow you to find out in more detail what the problem is. In my case I forgot to code in the password in the connection string.

Afterwards, you can check the “Enable the Visual Studio hosting process” option again.

Unrecognized configuration section userSettings.

Ok so you might find this interesting. I was changing one of my dot net programs lately to no longer rely on user settings. Once I deleted all user settings, I received the following error: “Unrecognized configuration section userSettings”.
The solution to this is to load the user.config file into notepad and delete the entire userSettings section from the file.  Then rebuild your program and it will work again.

Closing a Form Via the Red X

So someone posed this question to me. How do you cancel the close event on the form. This usually occurs when the user clicks the “red x” button on the form.
Here is what you do:
Private Sub dialog_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim dlgRes As Windows.Forms.DialogResult
dlgRes = MessageBox.Show(“Are you sure you wish to exit?”, “Closing”, MessageBoxButtons.YesNo, MessageBoxIcon.Information)
If dlgRes = Windows.Forms.DialogResult.Yes Then
Me.DialogResult = Windows.Forms.DialogResult.Yes
e.Cancel = False
Else
e.Cancel = True
End If
End Sub
Notice this is for the FormClosing event. This event uses a special set of event arguments called the FormClosingEventArgs. There is a property you can set that will cancel the close process named cancel.
The reason I am posting this is that while this seems so very obvious, it is suprisingly difficult to find this information for a new programmer so hopefully this will get tagged more appropriately in Google’s search engine.

Dot Net User Settings Vs Application Settings

Application and user settings in .Net are very simple to take advantage of. But how are they different?
Application settings are stored in the applications config file (XML document). Application settings cannot be changed while the program is running. So if you make a change in the config file while the program is running those changes will not be reflected until you restart the program. As an example, connection strings are a great thing to save here.
User settings are initially stored in the config file. The first time the program gets run it takes the values in the config file and loads them into a memory block for the program. Once you close the program all settings that were changed while the program was running are then saved in this block of memory. You can also call the method My.Settings.Saver() which will save the settings prior to the termination of the program. Great things to save in this are object that the user can manipulate and you want to save that data when they leave the program.
You might not believe me with the user settings but try it out yourself. Create a small project that saves some settings to a user setting. Then open the program in your favorite hex editor. Search for the setting that you saved, you will find it!

Error MSB3482: SignTool reported an error ‘Keyset does not exist’.

So I got this today: error MSB3482: SignTool reported an error ‘Keyset does not exist’. I was trying to publish a project in Visual Studio 2005. Here is the resolution:
Right click the ClickOnce key marked with the PFX extension in your projects folder, install it and try to publish again.
The cause apparently was that I changed the configuration of the compiling. Changing them back to the original state did not work because the damage was done.
Let me know if this helps!