/// <summary>
        /// Loads images from database using asynchronous request processing.
        /// </summary>
        public void GetImagesAsync()
        {
            AsyncManager.Timeout = 10000;

            ViewBag.Images = new ArrayList();
            ViewBag.Tables = new ArrayList();
            DatabaseWorker.connectDB();
            DatabaseWorker dw = new DatabaseWorker();
            for (int j = 0; j < 10; j++)
            {
                int count = dw.intQueryDB("select count(*) from Images");

                for (int i = 1; i <= count; i++)
                {
                    AsyncManager.OutstandingOperations.Increment();
                    AsyncWorker l = new AsyncWorker();
                    // Register the event handler to be notified when the async operation finishes
                    l.LoadDataCompleted += (sender, e) =>
                    {
                        // Place image contents in an array of images in viewbag
                        ViewBag.Images.Add("data:image/jpeg;base64," + @e.ImageContents);

                        AsyncManager.OutstandingOperations.Decrement();
                    };

                    // Execute async method (automatically on separate thread)
                    l.LoadDBImageAsync("select image from Images where imageID = " + i + " and exists (select * from ArticleAttachments where ImageID = " + i + ")");

                }
            }
            DatabaseWorker.disconnectDB();
        }
        /// <summary>
        /// Loads images from database synchronously.
        /// </summary>
        /// <returns>View of images</returns>
        public ActionResult GetImagesSynchronous()
        {
            DatabaseWorker dw = new DatabaseWorker();
            DatabaseWorker.connectDB();
            ViewBag.Images = new ArrayList();
            ViewBag.Tables = new ArrayList();
            for (int j = 0; j < 10; j++)
            {
                int count = dw.intQueryDB("select count(*) from Images");

                for (int i = 1; i <= count; i++)
                {
                    byte[] contents = dw.binaryQueryDB("select image from Images where imageID = " + i + " and exists (select * from ArticleAttachments where ImageID = " + i + ")");

                    // Place image contents in an array of images in viewbag
                    ViewBag.Images.Add("data:image/jpeg;base64," + Convert.ToBase64String(contents));

                }
            }
            DatabaseWorker.disconnectDB();
            ViewBag.Title = "Synchronous Test Loading Media From Database";
            return View("RegularQueries");
        }
        public ActionResult GetMediaCache()
        {
            DatabaseWorker dw = new DatabaseWorker();
            DatabaseWorker.connectDB();
            ViewBag.Tables = new ArrayList();
            ViewBag.Images = new ArrayList();
            for (int j = 0; j < 10; j++)
            {
                int count = dw.intQueryDB("select count(*) from Images");

                for (int i = 1; i <= count; i++)
                {
                    byte[] contents;
                    object cached = HttpRuntime.Cache.Get("DB.Images." + i);
                    if (cached == null)
                    {
                        contents = dw.binaryQueryDB("select image from Images where imageID = " + i + " and exists (select * from ArticleAttachments where ImageID = " + i + ")");
                        HttpRuntime.Cache.Insert("DB.Images." + i, contents, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 1, 0));
                    }
                    else
                    {
                        contents = (byte[])cached;
                    }

                    ViewBag.Images.Add("data:image/jpeg;base64," + Convert.ToBase64String(contents));

                }
            }

            DatabaseWorker.disconnectDB();
            ViewBag.Title = "Caching Test Loading Media From Database";
            return View("RegularQueries");
        }