Esempio n. 1
0
        /// <summary>
        /// Begins a new task in it's own thread. The target should be a static function
        /// that takes a single argument of type Object (which is a Guid object that
        /// identifies the AjaxTask object).
        /// </summary>
        /// <param name="target">The function to execute in a new thread.</param>
        /// <returns>The Guid that identifies the task being executed.</returns>
        /// <example>
        /// static void Worker(Object guid)
        /// {
        ///     // Do work
        /// }
        ///
        /// AjaxTask.BeginTask(MyClass.Worker);
        /// </example>
        static public Guid BeginTask(WaitCallback target)
        {
            AjaxTask task;


            task = new AjaxTask();
            task.Save();
            ThreadPool.QueueUserWorkItem(target, task.GUID);

            return(task.GUID);
        }
        /// <summary>
        /// Process the request for information about the AJAX task
        /// specified by the GUID.
        /// </summary>
        /// <param name="context">Context identifying the current web request.</param>
        public void ProcessRequest(HttpContext context)
        {
            AjaxTask task;

            task = new AjaxTask(new Guid(context.Request.QueryString["guid"].ToString()));

            context.Response.ContentType = "text/plain";
            context.Response.Write(
                "{ \"status\": \"" + task.Status.ToString() + "\"" +
                ", \"progress\": \"" + task.Progress.ToString() + "\"" +
                ", \"message\": \"" + task.Message.Replace("\"", "\\\"") + "\" }");
        }