I would not be wrong if I say that most computers these days are 64 bit. 64 bit offers many advantages over 32 bits and in general there is not much sense to install 32 bit OS pretty much anywhere, except maybe for some 32 bit virtual machine with less than 4 Gb of RAM, because in general 32 bit OS takes less memory. But even then, it is better to have 64 bit and just have couple of services running on it.

But at the same time, it is still common to run 32 code on it. For example, if you have IIS in many cases it has sense to run 32-bit worker process. Main reason behind that 32-bit

Recently I got email from customer, that our product consumes relatively lot of CPU on idle. About 3%-7%. He is using old notebook and as result fan is constantly cycles between on and off state and it is really annoying. I decided to check this because very often it could be sign of bigger problems.

Usually for cases like this I am asking customer to run PerfView to collect events that happens during problematic time. It is quite useful application; it is developed by Microsoft and completely free. It has quite unusual interface and requires some learning. There have links to learning videos from app itself.

Anyway, customer was nice and provided quite a few PerfView captures in different state

Case of frozen PeekMessage

Recently I was investigating why our application freezes during certain operations. After collecting few dump files, I found that every single time application freezes in quite old code that was written about 20 years ago. Loading documents could be quite long, and some person decided that it would be good idea if user can press Escape and cancel loading. To detect key press, that code calls something like this:
PeekMessage(Msg, CurrentFormHandle, WM_KeyFirst, WM_KeyLast, PM_Remove Or PM_NoYield)

Callstack looks like this:

win32u!NtUserPeekMessage+0x14
user32!_PeekMessage+0x43
user32!PeekMessageW+0x143

It looks quite innocent and I do not see any reason why it should hang. After some thinking I came with two theories:

  1. CurrentFormHandle returns invalid window handle that got reused by some thread that is sleeping
  2. Code that calls PeekMessage has infinite loop and PeekMessage is just took more time and appears in crash dumps.

Recently I found code that looks like this:
 

        static async Task Main(string[] args)
        {
            const int MaxLines = 10000;
            string line;
            List<string> lines = new List<string>();
            Stopwatch stopwatch = Stopwatch.StartNew();

            using var reader = new StreamReader(args[0]);
            while ((line = await reader.ReadLineAsync()) != null)
            {
                if (lines.Count >= MaxLines)
                {
                    lines.Clear();
                }

                lines.Add(line);
            }

            Console.WriteLine(stopwatch.ElapsedMilliseconds);
        }

As you can see this code is written “by the book”, everything is async: Main function is async, reading from file is async, and looks like this code is good. And if you ask people around which version would be faster: this one or non-async you will get mixed result. Some will say that async version will be faster,

Long-long time ago, our company created internal test tool that test web API for our servers. That tool simulates requests from our application, and it is using WinInet API. Tool always connection to test servers that are recreated every few days, it contains only test data. As this is testing server for our real production server, test tool using HTTPS protocol. But because it is using only for tests, it does have proper SSL certificate. Deploy script just install some self-signed certificate. Obviously testing tool cannot work by with that type of certificate and instead it just passes INTERNET_FLAG_IGNORE_CERT_CN_INVALID to HttpOpenRequest. Everything worked just fine for many years.

But several years ago, we discovered that our test tool

Some time ago I did play with Unity and when I was searching for help, I always stumble on articles comparing Unity and Unreal Engine. And few days ago, I decided to check Unreal Engine 4.

Usually when I try to learn something new, I find some tutorial and follow it. And as you can imagine, at the beginning any tutorial will take a lot of time. And obviously it would be nice to save your work periodically, just to save time if everything will go wrong. Also, at the beginning you can press or click something without knowing what you did, and everything will go wrong, and you will spend enormous amount of time figuring it out.

As result

AppStream from Amazon is service that allows to have Remote Desktop Session in your browser. Our company is using it to do evaluation of our software for potential customers. Customers can play with, explore it features etc, before buy. On other side, we can see what people are struggling it and adjust our software.

We were using it for some time, but recent Chrome update broke it. Safari stopped working some time before that. Now instead of opening remote session, we got 404 from Amazon. I believe it happens because Chrome stopped providing cooking for embedded iframe. And following post will show, how to fix it.

Normally service works like this. Web page calls some service on backend to get

Some time ago, Internet Explorer (IE for short) won over Netscape Navigator. As result there was quite interesting situation: there were quite few areas were IE did not respect standards at all or did not respect them completely. And when new browsers (Firefox and Opera) tried to gain some popularity, they immediately did hit hard concrete wall with their head: web sites do not work properly in new browsers. This happened mainly because other browsers actually did try to follow standards, but most web sites were designed for Internet Explorer that does not respect standards.

During that phase, most web site designers said pretty much that: “everybody uses IE, why should I care about browser that has 1%-2% of marker

  •   Posted in:
  • .NET

I was investigating some dead lock that happens in our application. Here is call stack of main thread:

ntdll!NtWaitForSingleObject+0x14
KERNELBASE!WaitForSingleObjectEx+0x93
clr!CLREventWaitHelper2+0x3c
clr!CLREventWaitHelper+0x1f
clr!CLREventBase::WaitEx+0x71
clr!WKS::GCHeap::WaitUntilGCComplete+0x2e
clr!Thread::RareDisablePreemptiveGC+0x18f
clr!StubRareDisableHRWorker+0x38
clr!COMToCLRWorker+0x19d612
clr!GenericComCallStub+0x57
SomeDll!SomeFunction+0x62
ntdll!LdrpCallInitRoutine+0x6f
ntdll!LdrpInitializeNode+0x1c1
ntdll!LdrpInitializeGraphRecurse+0x80
ntdll!LdrpPrepareModuleForExecution+0xc5
ntdll!LdrpLoadDllInternal+0x199
ntdll!LdrpLoadDll+0xa8
ntdll!LdrLoadDll+0xe4
hmpalert!CVCCP+0x67eb
KERNELBASE!LoadLibraryExW+0x161
KERNELBASE!LoadLibraryExA+0x31
KERNELBASE!LoadLibraryA+0x3f
0x00007ffa`0fec9ece
...
clr!ExecuteEXE+0x3f
clr!_CorExeMainInternal+0xb2
clr!CorExeMain+0x14
mscoreei!CorExeMain+0x112
mscoree!CorExeMain_Exported+0x6c
kernel32!BaseThreadInitThunk+0x14
ntdll!RtlUserThreadStart+0x21

Ok, it looks like main thread is waiting for GC to finish. But what is GC doing? And it looks GC related code is here:

ntdll!NtWaitForSingleObject+0x14
KERNELBASE!WaitForSingleObjectEx+0x93
clr!CLREventWaitHelper2+0x3c
clr!CLREventWaitHelper+0x1f
clr!CLREventBase::WaitEx+0x71
clr!`anonymous namespace'::CreateSuspendableThread+0x10c
clr!GCToEEInterface::CreateThread+0x170
clr!WKS::gc_heap::prepare_bgc_thread+0x4c
clr!WKS::gc_heap::garbage_collect+0x1836b7
clr!WKS::GCHeap::GarbageCollectGeneration+0xef
clr!WKS::GCHeap::Alloc+0x29c
clr!JIT_New+0x339
...
mscorlib_ni!System.Threading.Tasks.Task.Execute()$##6003FAD+0x47
mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)$##6003AEF+0x172
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)$##6003AEE+0x15
mscorlib_ni!System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)$##6003FBA+0x231
mscorlib_ni!System.Threading.Tasks.Task.ExecuteEntry(Boolean)$##6003FB9+0xa1
mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)$##6003AEF+0x172
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)$##6003AEE+0x15
mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)$##6003AED+0x55
mscorlib_ni!System.Threading.ThreadHelper.ThreadStart(System.Object)$##6003BFF+0x60
clr!Thread::intermediateThreadProc+0x8b
kernel32!BaseThreadInitThunk+0x14
ntdll!RtlUserThreadStart+0x21

All other