/// <summary> /// Perform a blog operation with a timeout. If the operation could not be completed for any reason (including /// an invalid blog, no credentials, a network error, or a timeout) then null is returned. /// </summary> /// <param name="owner"></param> /// <param name="blogId"></param> /// <param name="operation"></param> /// <param name="timeoutMs"></param> /// <returns></returns> public static object PerformBlogOperationWithTimeout(string blogId, BlogClientOperation operation, int timeoutMs, bool verifyCredentials) { try { // null for invalid blogs if (!BlogSettings.BlogIdIsValid(blogId)) { return(null); } // null if the user can't authenticate if (verifyCredentials) { using (Blog blog = new Blog(blogId)) { if (!blog.VerifyCredentials()) { return(null); } } } // fire up the thread BlogClientOperationThread operationThread = new BlogClientOperationThread(blogId, operation); Thread thread = ThreadHelper.NewThread(new ThreadStart(operationThread.ThreadMain), "BlogClientOperationThread", true, false, true); thread.Start(); // wait for it to complete thread.Join(timeoutMs); // return the result return(operationThread.Result); } catch (Exception ex) { Trace.WriteLine("Exception occurred performing BlogOperation: " + ex.ToString()); return(null); } }
/// <summary> /// Perform a blog operation with a timeout. If the operation could not be completed for any reason (including /// an invalid blog, no credentials, a network error, or a timeout) then null is returned. /// </summary> /// <param name="owner"></param> /// <param name="blogId"></param> /// <param name="operation"></param> /// <param name="timeoutMs"></param> /// <returns></returns> public static object PerformBlogOperationWithTimeout(string blogId, BlogClientOperation operation, int timeoutMs, bool verifyCredentials) { try { // null for invalid blogs if (!BlogSettings.BlogIdIsValid(blogId)) return null; // null if the user can't authenticate if (verifyCredentials) { using (Blog blog = new Blog(blogId)) { if (!blog.VerifyCredentials()) return null; } } // fire up the thread BlogClientOperationThread operationThread = new BlogClientOperationThread(blogId, operation); Thread thread = ThreadHelper.NewThread(new ThreadStart(operationThread.ThreadMain), "BlogClientOperationThread", true, false, true); thread.Start(); // wait for it to complete thread.Join(timeoutMs); // return the result return operationThread.Result; } catch (Exception ex) { Trace.WriteLine("Exception occurred performing BlogOperation: " + ex.ToString()); return null; } }