Queueing items to ThreadPool

The simplicity of this approach is astonishing. And it was in .net since .net 4, but our eyes are not always looking in the direction we should.


The method is offering overload with Action delegate and argument. Actually the argument is significant. If it is blocking function it will Queue the new action only when it stops blocking.

Thus the simple http server can only be:

while(true) {
   ThreadPool.QueueUserWorkItem(Process, listener.GetContext());    

void Process(object o)
 {    var context = o as HttpListenerContext;
    // process request and make response

We are waiting until someone connects. And yes it only processes maximally pool-size amount of concurrent connections. But that is another story I think. I wanted to share the beauty of this solution.

Inspiration was from

Inspecting Wix Managed Custom Actions


Wix Toolset allows creating .net managed Custom actions for the Windows Installers. Windows Installer only supports

Custom Actions in .exe, VBScript, JScript and .dll

The tool which marshals std call to native dll function into managed code is called Deployment Tools Foundation (DTF).


When you open an Msi with managed CA in Orca, you will see it as a native .dll in Binary table. You can also notice WixCA binary attachment named after your binary , which basically encapsulates all DTF code which extracts managed CA.

For example your binary in a .wxs file:

<Binary Id=”CustomActionBinary” SourceFile=”$(var.CA.TargetDir)$(var.CA.TargetName).CA.dll”/>

If you export your binary as .dll and open it in Dependency Walker you will see your Custom Action name as exported function in .dll


The CA binary is actually created by MakeSfxCA, which is actually attaching all CA managed binaries and WixCA in a .dll as Windows Cab file.

For example 7Zip can extract cabinet files to actual content:


And here is how it looks in ILSpy


Full HTTP/2 Support in Windows 10

The Windows 10 supports HTTP/2 not only in its IE12 browser, but also in its IIS. IIS will serve static & dynamic ASPX pages with the new protocol automatically without any additional settings.

Only drawback currently stated by MS here is that sites needs to support HTTPS.

The Browser support

The HTTP/2 is implemented as protocol in WinINet and can be enabled in the Internet Options (IE –> Tools -> Internet Options).

It means any other application when enabled can take advantage of consuming HTTP/2 content. (Namely WWA Hosted Metro applications)

Picture: Enabling HTTP/2 in Internet Options

The Server Support

The server implementation of HTTP/2 is now full full IIS based implementation. It is quite improvement from already published HTTP/2 in Katana which is limited to just „TLSv1.2 and DHE or EDCHE with GCM cipher suite“.

The implementation is most probably inside the HTTP kernel driver called http.sys (as investigated here) and can be used by any HttpListener on Win 10 Tech Preview.

Picture: Internet Explorer 12 with a site using HTTP/2 hosted on IIS

Here is how to create simple HTTPS Site on Win10 IIS

1. Create SSL Certificate in IIS.
Open the IIS Manager, select the server name and from the Features open the Server Certificates

Then select Create Self Signed Certificate in the Right pane:

In the Create Self-Signed Certificate dialog, just fill the name:


2. Created new HTTPS Site in the IIS
Select Add Website from the IIS Hostname in the manager

Fill in the name, physical path, the binding type to HTTPS. The Hostname is usefull to fill in in case of remote access to your Win10. Then you have to select previously created certificate.

Now, we have created the new IIS Site. It will already serve the requests, but we dont have anything to serve yet. I crated simple index.aspx file in my WebSite path (c:\inetpub\testsite) with this content:

<form runat=”server”>
<% Response.Write(“Hello, World !”); %>

Other browsers:

I have also tried accessing using IE 11, which still uses just HTTPS for that site:


In the other hand, Firefox Nightly already implements the HTTP/2 correctly:


Windows 10 is one of first with the full stack implementation of HTTP/2 today. We can now experiment more with our ASPX applications speed.

Firefox Nightly in Visual Studio

Building Firefox nightly

The Mozilla’s documentation about compiling Firefox is pretty straightforward. On Windows, you basically need just

  1. Build prerequisities which mostly means some Visual Studio edition + MozillaBuild package.
  2. Second step is just to go to extracted MozillaBuild package folder and start apropriate command prompt (bash + some paths).
  3. In this new command window, get sources using hg (Mercurial client, which is part of MozillaBuild package & paths).
  4. Set to some folder where you would like to deploy Firefox sources and start hg. The command is:

    hg clone https://hg.mozilla.org/mozilla-central

  5. start the build in using:
    ./mach build
  6. Start the built Firefox, using
    ./mach run

Using Firefox nightly from Visual Studio

Now you should have Firefox running, built by the Mozilla scripts. There is no way how to build everything in Visual Studio, but you can open the browser in that and debug it. Its limited to just browser itself and some internal libraries are not included, for example NSS (library serving the work with HTTPS). To generate the Visual Studio project you need to return to your MozillaBuild prompt, (you should sill be in your mozilla sources folder) and enter:

./mach build-backend -b VisualStudio

after this command, you will get a .sln file generated in your Firefox sources folder under


You can open this in Visual Studio (2013 in my case) without a problem.

Enable logging of LOG messages

When you will be looking at code you will find, that there is a pretty amount of log messages being logged using LOG or LOG3 macros. These are actually logging if you enable logging for your module. If you want to log everything, just set these Windows variables before starting new firefox.exe:
set NSPR_LOG_FILE=%TEMP%\fflog.txt

Then the log file is generated under %TEMP%\fflog.txt. To open just use

notepad.exe %TEMP%\fflog.txt

Debugging Firefox in Visual Studio

Its actually not a big deal, just attach your Visual Studio to running firefox.exe and set a breakpoint and you are good to go.

Testing HTTP 2.0 in a browser

You most probably already know how the good old buddy HTTP works. Its very simple, very straightforward and also very old. After some evolution, started by Google with SPDY, we currently have draft of a IETF standard for v 2.0 of this protocol, called also HTTP/2. All this evolution was driven by the desire to make web page loading faster and eventually to reduce the data amounts downloaded on our phones.

The best way is to try. The http2 Implementations tracking page shows that there is a Microsoft implementation, revealing a HTTP/2 supporting server url at:


Also, the current Firefox Nightly can be enabled to support this version. The steps to enable Http/2 in it are to open about:config and switch these two to true:

  • network.http.spdy.enabled.http2draft
  • security.ssl.enable_alpn

When enabled in FF Nightly, you can navigate to


Which is a page showing one of HTTP/2 advantages called Multiplexing, which is ability to download large amount of resources simultaneously. The testing page should load he left image much faster. Also when you look at the request, you will see HTTP 2.0, like on following screen.


ManualResetEvent vs AutoResetEvent

I want to signal all of my threads waiting for WaitHandle and move them from the Wait Queue to Ready Queue.

There is a small, but significant difference between these two. The main difference comes from the names, when in AutoResetEvent signales (releases) one thread, waiting in the Wait queue and then automatically returns to non-signaled state. Strictly said:
AutoResetEvent will pick and signal just for one thread of more waiting threads.

In the other hand, using ManualResetEvent, you have much more control over the situation. When some thread (producer) will signal (Set), all waiting threads are signaled (released) and enqued to the Ready Queue. Which means they continue from their Wait command.
In this situation you are getting more control in your hands to pick up, which of the waiting threads should take the resource, or process some workitem. The rest of threads can be put in consequent waiting if needed.


I have a bunch of threads, which are waiting for signal.

First lets try what happens with AutoResetEvent:

Clearly shows how just first thread is signalled

ManualResetEvent example

This looks much better, all the waiting threads received the signal

And finally, the code which produced this:

class Program
        static ManualResetEvent mre;
        static void Main(string[] args)
            mre = new ManualResetEvent(false);
            var maxT = 3;
            var threads = new List();
            for (int i = 0; i < maxT; i++)
                var t1 = new Thread(Program.T1Proc);
            Console.WriteLine("Sleeping for 1 sec");
        static void T1Proc(object state)
            Console.WriteLine(" thread " + state + " waiting");
            bool received = mre.WaitOne(5000);
            if (received)
                Console.WriteLine(" thread " + state + " received signal");
                Console.WriteLine(" thread " + state + " not received signal");

How to reset OpenWrt root password

It turned out that after few months of using my OpenWrt properly, I have completelly lost my root password and couldn’t connect to my router’s OpenWrt LuCi.

Fortuantelly, OpenWrt has a failsafe mode, where you can set things back up.

How to get to OpenWrt Failsafe mode:

  1. Reset the router
  2. Wait for the DMZ light (Second left light started blinking)
  3. Hold Router reset button for 2 seconds
  4. Connect your’r PC‘s Ethernet Cable to Router’s WAN port (You cannot access Failsafe when connected to any of LAN ports
  5. Set your PC IP Address to, NetMask to, GW to
  6. ipOpen Telnet connection to
  7. openwrt_failsafeType mount_root to mount your Router’s FS to Read/Write mode
  8. Type passwd to change root password
  9. openwrt_passwdSwich your LAN Ethernet cable from WAN port on Router back to some LAN one
  10. Restart the router