Showing tag results for Code

Aug 14, 2014
Post comments count0
Post likes count0

Customers not getting the widgets they paid for if they click too fast -or- In C#, the += operator is not merely not guaranteed to be atomic, it is guaranteed not to be atomic

Raymond Chen
Raymond Chen

In the C# language, operation/assignment such as are explicitly not atomic. But you already knew this, at least for properties. Recall that properties are syntactic sugar for method calls. A property declaration is internally converted to the equivalent of Accessing a property is similarly transformed. Note that the only operations you c...

Code
Aug 13, 2014
Post comments count0
Post likes count0

Keep your eye on the code page: C# edition (the mysterious third code page)

Raymond Chen
Raymond Chen

A customer was having trouble manipulating the console from a C# program: We found that C# can read only ASCII data from the console. If we try to read non-ASCII data, we get garbage. Observe that this program is unable to read the Å and ö characters. They come back as garbage. Although there are three code pages that have spec...

Code
Aug 12, 2014
Post comments count0
Post likes count0

Keep your eye on the code page: C# edition (warning about DllImport)

Raymond Chen
Raymond Chen

Often, we receive problem reports from customers who failed to keep their eye on the code page. Does the function support files with non-ASCII characters in their names? We find that the function either fails outright or returns question marks when asked to provide information for files with non-ASCII characters in their name. If we ask for...

Code
Aug 11, 2014
Post comments count0
Post likes count0

If you want to set a thread's apartment model via Thread.CurrentThread.ApartmentState, you need to act quickly

Raymond Chen
Raymond Chen

Welcome to CLR Week 2014. Don't worry, it'll be over in a few days. A customer wanted to know why their was displaying the infamous Current thread must be set to single thread apartment (STA) mode before OLE calls can be made error. "Even though we set the to , the apartment state is still . Curiously, if we put the above code in a standalo...

Code
Aug 8, 2014
Post comments count0
Post likes count0

The case of the orphaned LpdrLoaderLock critical section

Raymond Chen
Raymond Chen

A customer found that under heavy load, their application would occasionally hang. Debugging the hang shows that everybody was waiting for the critical section. The catch was that the critical section was reported as locked, but the owner thread did not exist. How can a critical section be owned by thread that no longer exists? There are two...

Code
Aug 7, 2014
Post comments count0
Post likes count1

Since clean-up functions can't fail, you have to soldier on

Raymond Chen
Raymond Chen

Clean-up functions can't fail, so what do you do if you encounter a failure in your clean-up function? You have to keep cleaning up. Some people like to follow this pattern for error checking: And some like to put it inside a cute flow control macro like or even Whatever floats your boat. But you have to be careful if using this p...

Code
Aug 6, 2014
Post comments count0
Post likes count0

Why does Explorer say "File too large" for my custom file system, when the problem has nothing to do with the file being too large (heck it's not even a file)

Raymond Chen
Raymond Chen

When Explorer copies files around, it doesn't really know what the maximum file size supported by any file system happens to be. (That information is not reported by .) So it guesses. If the file system name is or , then Explorer assumes that the maximum file size is 4GB − 1. Also, if a file operation fails with the error , and Explorer ca...

Code
Aug 4, 2014
Post comments count0
Post likes count0

Enumerating the ways of choosing teams in a group of players

Raymond Chen
Raymond Chen

Suppose you have a bunch of people, and you want to break them up into m teams of size n. (Therefore you have a total of nm people.) Today's Little Program will enumerate the ways this can be done. Formally, let's say that you have a collection of size nm, and you want to enumerate the ways of partitioning the collection into m subsets, each sub...

Code
Aug 1, 2014
Post comments count0
Post likes count0

Before claiming that a function doesn't work, you should check what you're passing to it and what it returns

Raymond Chen
Raymond Chen

Before claiming that a function doesn't work, you should check what you're passing to it and what it returns, because it may be that the function is behaving just fine and the problem is elsewhere. The function does not appear to support directories with Unicode characters in their names. The correct directory name is obtained if it contain...

Code
Jul 31, 2014
Post comments count0
Post likes count0

What is the strange garbage-looking string in the "command" value of a static verb?

Raymond Chen
Raymond Chen

A customer from a major software vendor asked, "What is the significance of the value that can be found under . It appears to be a copy of the default value, but with the program name replaced with apparent garbage. We've seen this both with Microsoft products as well as products by other companies. There is no mention of this value in the docume...

Code