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!

Advertisement

A ClickOnce gotcha – FIPS algorithms

If you are using FIPS, your ClickOnce applications might not work. I ran into this bug running BookSmarts, an application I wrote. Turned FIPS on and started receiving errors.

The issue is that enabling FIPS makes the mechanism that verifies the validity of ClickOnce applications fail every time.

The article, a very long one, can be found here: https://support.microsoft.com/en-us/kb/811833

Just keep this in mind if you are trying to support someone who is the odd ball out.

Note: Enabling/Disabling FIPS in Windows is done through the registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy\Enabled (DWORD)

1 is on, 0 is off

When changing this setting, it’s necessary to reboot the computer.

Powershell ~ Shorten Shortcut Names

Renaming Files

Here is something I just came up with. It is a really short Powershell one-liner to remove the annoying ‘- Shortcut’ from your shortcuts.

dir “*- Shortcut*” | foreach{ren -Path $_.Name -NewName $_.Name.Replace(” – Shortcut”,””)}

It is a good idea to execute it first with -whatif in the foreach loop.

Note: Be sure to be in the desktop directory when you run this.

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

Visual Basic 2010 Object and List Initialization

I just found this out and I am really excited about it! The With & From are cooler than ever!

Check this out:

Module Module1
Private Class TestClass
Public Property Subject As String
Public Property Grade As String
Public Property Student As String
End Class
Sub Main()
Dim myTest As New TestClass With {.Grade = "A+", .Student = "Myself", .Subject = "Advanced Chromotography"}

Dim test As New System.Collections.Generic.List(Of TestClass) From {
myTest,
New TestClass With {.Subject = "Math", .Student = "John Bowman", .Grade = "B"}}

End Sub
End Module

The With and From are now part of the declaration statement, saving even more real estate on the screen.

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.

Canceled By User ~ Debugging CLR Objects in SQL Server and Visual Studio

So you enabled CLR debugging on your TEST SQL Server (don’t ever do this on production!)

You are trying to debug but you get a message “Canceled by user” in the Output window in Visual Studio. Here is the answer, you have to enable the ports on BOTH your workstation and the SQL Server machine.

Add the following inbound exceptions to both machines:
TCP: 135
UDP: 400,500

On your WORKSTATION:
Add the program devenv.exe to your exceptions list in your firewall.

This will worked for me. Let me know if you had a different solution.

SQL Server ~ Creating a CLR User Defined Function Error 181

Cannot use the OUTPUT option in DECLARE or CREATE FUNCTION statement

So this may or may not trip you up. If you are like me, you want thing to run fast. One of those ways is to pass a reference to a variable as opposed to passing a copy of the value to the function. In .Net this works well, however SQL Server translates the byref to it’s equivalent which is OUTPUT option. Simply bite the bullet and change the function to have all of your parameters to byval and you are good to go.

Hopefully I saved you some time and agrivation.

VB.Net C# Designtime Error ~ ‘.ctor’ is not a valid identifier.

Tired of searching you project for that string? The answer is simple, which was proposed by Vladmir from Serbia on MSDN. The name of your class or form shares it’s name with a function or subroutine contained within that class. Like below:

public class Form1

private sub Form1()

end sub

end class

Changing the name of the method will fix this issue.

OracleConnection ~ Connection String Nightmare

I spent quite a bit of time today debugging an oracleconnection object. It would fail everytime the connection string property was set. This is what I would recieve in the error log:

Faulting module name: KERNELBASE.dll, version: 6.1.7601.17651, time stamp: 0x4e2111c0

Exception code: 0xe0434f4d

Fault offset: 0x0000d36f

I didn’t get to far Duck Duck Go’ing (or Googling) on this so I threw the assignment into an try catch block. I got an error  “Connection string is not well formed”. Connectionstrings.com had a great section on Oracle so I copied/pasted it into my code changing the pertinent data. Same issue.

After trying several things I discovered that the connection strings for Oracle cannot have a trailing semi-colon.

Data Source=IDWorks;User Id=IDWorks;Password=idw;

Data Source=IDWorks;User Id=IDWorks;Password=idw

Hope this saved you some time!