private void ProduceThread()
    {
        IActiveDesktop ad = (IActiveDesktop) new ActiveDesktop();

        _signal.Set();
        while (true)
        {
            _signal.WaitOne();

            Job query;
            while (_queue.TryDequeue(out query))
            {
                object  retval = null;
                dynamic input  = query.input;
                try
                {
                    switch (query.method_idx)
                    {
                    case 0: ad.ApplyChanges((uint)input.dwFlags); break;

                    case 1: retval = StringDelegate((b) => ad.GetWallpaper(b, (uint)b.Capacity, (uint)input.dwFlags)); break;

                    case 2: ad.SetWallpaper((string)input.pwszWallpaper); break;

                    case 3: ad.GetWallpaperOptions((WallpaperOpt)(retval = new WallpaperOpt())); break;

                    case 4: ad.SetWallpaperOptions(new WallpaperOpt((dynamic)input.pwpo)); break;

                    case 5: retval = StringDelegate((b) => ad.GetPattern(b, (uint)b.Capacity)); break;

                    case 6: ad.SetPattern((string)input.pwszPattern); break;

                    case 7: ad.GetDesktopItemOptions((ComponentsOpt)(retval = new ComponentsOpt())); break;

                    case 8: ad.SetDesktopItemOptions(new ComponentsOpt((dynamic)input.pco)); break;

                    case 9: ad.AddDesktopItem(new Component((dynamic)input.pcomp)); break;

                    case 10: ad.AddDesktopItemWIthUI((IntPtr)input.hwnd, new Component((dynamic)input.pcomp), (uint)input.dwFlags); break;

                    case 11: ad.ModifyDesktopItem((Component)(retval = new Component((dynamic)input.pcomp)), (uint)input.dwFlags); break;

                    case 12: ad.RemoveDesktopItem(new Component((dynamic)input.pcomp)); break;

                    case 13: int pcItems; ad.GetDesktopItemCount(out pcItems); retval = pcItems; break;

                    case 14: ad.GetDesktopItem((int)input.nComponent, (Component)(retval = new Component((dynamic)input.pcomp))); break;

                    case 15: ad.GetDesktopItemByID((ulong)input.dwID, (Component)(retval = new Component((dynamic)input.pcomp))); break;

                    case 16: ad.GenerateDesktopItemHtml((string)input.pwszFileName, new Component((dynamic)input.pcomp)); break;

                    case 17: ad.AddUrl((IntPtr)input.hwnd, (string)input.pszSource, new Component((dynamic)input.pcomp), (uint)input.dwFlags); break;

                    case 18: ad.GetDesktopItemBySource((string)input.pszSource, (Component)(retval = new Component((dynamic)input.pcomp))); break;
                    }
                    query.retval = retval;
                }
                catch (Exception e)
                {
                    query.e = e;
                }
                query._signal.Set();
            }
        }
    }