The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,861 other subscribers

Archive for the ‘C# 1.0’ Category

.NET/C#: workaround to solve small glitch with Visual Studio 2010, CodeRush with and string resources

Posted by jpluimers on 2012/08/08

CodeRush has a nice refactoring to extract a C# string into a resource.

There is a small glitch that when you press undo after that, and there was no string file in your project, then the empty resource file is not always saved.

Upon building your project, you will get an error like this:

---------------------------
Microsoft Visual Studio
---------------------------
The item 'Resources.resx' does not exist in the project directory. It may have been moved, renamed or deleted.
---------------------------
OK
---------------------------

The Resources.resx file is not visible in your Solution Explorer, so you cannot delete it there.

You have to manually edit your .csproj file and remove the Resources.resx reference there.

I’ve had this happen only a couple of times, and cannot yet reproduce this. Until I can reproduce, this is a workaround to remedy the effects.

–jeroen

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

C# code fragment of the week

Posted by jpluimers on 2012/07/24

Please don’t do your code like this:

        internal bool blnMDACResult = true;

        internal bool CheckMDACisOK(string eenMDAC, string strAdoDllPath)
        {
            FileVersionInfo AdoVersionInfo;

            try
            {
                AdoVersionInfo = FileVersionInfo.GetVersionInfo(strAdoDllPath);
                AdoDllVersion = new Version(AdoVersionInfo.ProductMajorPart, AdoVersionInfo.ProductMinorPart, AdoVersionInfo.ProductBuildPart, AdoVersionInfo.ProductPrivatePart);

                switch (eenMDAC)
                {
                    case "2.6":
                    case "2,6":
                        // MDAC 2.6 - 2.60.6526.0
                        Version MinimumVersion = new Version(2, 60, 6526, 0);
                        blnMDACResult = AdoDllVersion.CompareTo(MinimumVersion) >= 0;
                        break;

                    case "2.7":
                    case "2,7":
                        // MDAC 2.7 - 2.70.7713.0
                        Version MinimumVersion = new Version(2, 70, 7713, 0);
                        blnMDACResult = AdoDllVersion.CompareTo(MinimumVersion) >= 0;
                        break;

                    case "2.8":
                    case "2,8":
                        // MDAC 2.8 - 2.80.1022.0
                        Version MinimumVersion = new Version(2, 80, 1022, 0);
                        blnMDACResult = AdoDllVersion.CompareTo(MinimumVersion) >= 0;
                        break;

                    default:
                        // 2.9 and up
                        string numberDecimalSeparator = Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;
                        double dMinVersion = ConvertAppl.ToDouble(eenMDAC.Replace(".", numberDecimalSeparator));
                        double dVersion = ConvertAppl.ToDouble(AdoDllVersion.Major + ".".Replace(".", numberDecimalSeparator) + AdoDllVersion.Minor);
                        if (dVersion > dMinVersion)
                            blnMDACResult = true;
                        else
                            blnMDACResult = false;
                        break;
                }
            }
            catch
            {
                // Something went wrong, let's assume the version is ok. (trial on error)
                blnMDACResult = true;
                return blnMDACResult;
            }

            return blnMDACResult;

        }

–jeroen

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

Dear fellow programmer. If you aren’t experienced doing multi-threading, please don’t!

Posted by jpluimers on 2012/07/05

Recently I was asked to investigate a performance problem with a certain .NET application.

The first error I got when getting the app to build in Visual Studio 2010, and then run it was like this:

System.ComponentModel.InvalidAsynchronousStateException was caught
  Message=An error occurred invoking the method.  The destination thread no longer exists.
  Source=System.Windows.Forms
  StackTrace:
       at System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle waitHandle)
       at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
       at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
       at UI.Splash.SetStatus(String status) in C:\...\Splash.cs:line 395
       at UI.Menu.Main() in C:\...\Menu.cs:line 4275
  InnerException:

Someone built their own splash logic with multi-threading.

Funny that today, this got answered on StackOverflow by [WayBackmgie: [WayBack] multithreading – TMonitor synchronization / Application.ProcessMessages – Stack Overflow.

Though that is a Delphi link (and points to the nice libraries [Archive.is] AsynCalls and [WayBack] OmniThreadLibrary), the most important link it contains is to  [WayBackBorland Newsgroup Archive :: borland.public.delphi.internet.winsock :: Re: Disconnect TIdHttp in thread.

That sounds like a Delphi link too, but the subtitle “‘Ways to get into avoidable trouble with threads, V1.2′” hints the essence: it is a post that describes in an environment-agnostic way how to avoid multi-threading problems.

Recommended reading!

Anyway: Building multi-threaded code is hard. Even harder fleshing out all the corner cases and potential error conditions.

No matter what kind of programming environment: If you have not done lots of multi-threaded programming, then please don’t do it yourself: go ask someone that does know how to do it. Or better, try to avoid it.

I try to let libraries to the handling of multi-threading for me, if I use multi-threading at all, as others are far better at this than I am.

–jeroen

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Conference Topics, Conferences, Delphi, Development, Event, Java, Software Development, VB.NET, VBS, Visual Studio 2010, Visual Studio and tools, WinForms | 6 Comments »

Visual Studio and Delphi: Getting a new GUID in the code editor

Posted by jpluimers on 2012/06/28

Earlier this week, I already wrote about different idioms in different IDEs.

Here is another one, again a feature I don’t use often: getting a fresh GUID in the IDE. Read the rest of this entry »

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Delphi, Development, Software Development, Visual Studio and tools | 7 Comments »

C# Remove Duplicate Lines From Text File? – Stack Overflow

Posted by jpluimers on 2012/06/27

Recently I had to do a quick removal of duplicate lines in bunch of text files.

A quick search revealed that back in 2009, John Skeet came to the rescue with a couple of examples (:

--jeroen

via: C# Remove Duplicate Lines From Text File? – Stack Overflow.

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Jon Skeet, Software Development | 1 Comment »

Repeating characters into strings in C# and Delphi (via: .net – Best way to repeat a character in C# – Stack Overflow)

Posted by jpluimers on 2012/06/26

Switching back and forth between mainly Delphi and C#, sometimes it is hard to remember which idiom works best in each environment.

Recently, I had to dupe a lot of tab characters for some Tab-Delimited interface to an archaic system.

I remembered the Delphi idiom: use the DupeString function as about Delphi explains (yes, I know: it dupes more than just characters).

In C#, these work best for me:

Small code sample of the first way (thanks CMS):

static string Tabs(int n)
{
    return new String('\t', n);
}

–jeroen

via: .net – Best way to repeat a character in C# – Stack Overflow.

Oh BTW: I have reduced my StackOverflow presence. It looks like the success of StackOverflow made them instantiate many moderators. A lot of those moderators work under the mantra “we follow the rules strictly, and favour punishment over encouragement” (some  even talk about “changing heritage“). That’s a real pity, as I see a lot of StackOverflow users get scared by the very active downvoting, question/answer closing and even deletion of material that is in essence valuable, if it were edited up a bit. Deleting content is always bad, as it increases the link rot that StackOverflow are trying to prevent in questions/answers as per their FAQ. Links are the foundation of the web.

Alas, devoting real attention to the quality of StackOverflow requires putting real energy in it, which for some of the moderators seems to be too much to ask.

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Delphi, Development, Pingback, Software Development, Stackoverflow | 5 Comments »

.NET/C# – WinForms splash screen research material

Posted by jpluimers on 2012/06/21

I’m in the midst of converting a suite of WinForms C# projects from a range of .NET versions (1.x till 3.x) to 4 totalling some million lines of code.

One of the problems is that some people hacked together some splash screen stuff using multi-threading, doing all sorts of things that was forbidden in .NET 1 (and broke in .NET 2+).

On my research list for getting this to work:

  1. Mahin Gupta | Winforms splash screen – Great work by Tom. which is an update of
  2. A Pretty Good Splash Screen in C# – CodeProject.

–jeroen

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, Development, Software Development, Visual Studio 2002, Visual Studio 2003, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools, WinForms | Leave a Comment »

WTF C# code of the month

Posted by jpluimers on 2012/03/14

When I come across code like this, I’m always astonished:

			catch(Exception ex)
			{
				string strMess = ex.Message;
			}

What was the person thinking when he wrote this? Did he get distracted and nobody else notice this before checking it into their version control system?

In the same module:

		private string ToString(object myVal)
		{
			try
			{
				if (myVal != System.DBNull.Value)
					return myVal.ToString().Trim();
			}
			catch{}

			return "";
		}

–jeroen

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »