首页 新闻 赞助 找找看

闹心了,求大神解惑!

0
悬赏园豆:10 [已关闭问题] 解决于 2015-08-31 15:15

异常信息如下:

CLR は、COM コンテキスト 0x5a9198a8 から COM コンテキスト 0x5a9199d0 へ 60 秒で移行できませんでした。ターゲット コンテキストおよびアパートメントを所有するスレッドが、ポンプしない待機を行っているか、Windows のメッセージを表示しないで非常に長い実行操作を処理しているかのどちらかです。この状態は通常、パフォーマンスを低下させたり、アプリケーションが応答していない状態および増え続けるメモリ使用を導く可能性があります。この問題を回避するには、すべての Single Thread Apartment (STA) のスレッドが、CoWaitForMultipleHandles のようなポンプする待機プリミティブを使用するか、長い実行操作中に定期的にメッセージをポンプしなければなりません。

 

我看不懂……

啥意思啊……

问题补充:

弄不下去了,这个过程是这样的,我要自动化检测在SharePoint Solution卸载后Solution的状态,发现retract完成后,自动点击remove进行删除。到点击卸载都没有问题,问题就出在点击卸载之后,过一会儿就会弹出这个提示。这个过程由于在多wfe环境下是很耗时的,所以我经历这一个过程要10分钟左右。每次都弹这个错误,我崩溃了。什么乱七八糟的看不懂啊……有没有大神解答一下啊????谢谢!

 

ContextSwitchDeadlock was detected
Message: CLR は、COM コンテキスト 0xd18760d8 から COM コンテキスト 0xd1876200 へ 60 秒で移行できませんでした。ターゲット コンテキストおよびアパートメントを所有するスレッドが、ポンプしない待機を行っているか、Windows のメッセージを表示しないで非常に長い実行操作を処理しているかのどちらかです。この状態は通常、パフォーマンスを低下させたり、アプリケーションが応答していない状態および増え続けるメモリ使用を導く可能性があります。この問題を回避するには、すべての Single Thread Apartment (STA) のスレッドが、CoWaitForMultipleHandles のようなポンプする待機プリミティブを使用するか、長い実行操作中に定期的にメッセージをポンプしなければなりません。

 

 

附上我的代码吧……麻烦了……出错的地方我用蓝色标注出来了:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.IO;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.UI;
using Selenium;
using System.Net;
using System.Runtime.InteropServices;
using System.Globalization;

namespace SharePoint_Solution_Auto_Deploy
{
    public partial class MainForm : Form
    {
        //To make the GetForegroundWindow possible.
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetForegroundWindow();
        //Form entry.
        public MainForm()
        {
            InitializeComponent();
            getSPWebApps(); 
        }
        //Add web apps to the combobox.
        private void getSPWebApps()
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications)
                    {
                        WebAppComBox.Items.Add(webApp.Name);
                    }
                });
            }
            catch (Exception ex)
            {
                WriteLog(ex);
            }
        }
        //Web application.
        private void WebAppsComBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            WebAppComBox.Text = WebAppComBox.SelectedItem.ToString();
            SPWebApplicationCollection webApps = SPWebService.ContentService.WebApplications;
            SPWebApplication webApp = webApps[WebAppComBox.Text];
            getSPSites(webApp);
        }
        //Site.
        private void getSPSites(SPWebApplication webApp)
        {
            SPSiteCollection sites = webApp.Sites;
            //Add前先清空列表中的老items。
            SiteComBox.Items.Clear();
            foreach (SPSite site in sites)
            {
                SiteComBox.Items.Add(site.Url.ToString());
            }
        }
        //Write log method.
        private static void WriteLog(Exception ex)
        {
            string logUrl = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\SeleniumAutoTest.txt";
            if (File.Exists(@logUrl))
            {
                using (FileStream fs = new FileStream(logUrl, FileMode.Append))
                {
                    using (StreamWriter sw = new StreamWriter(fs, Encoding.Default))
                    {
                        try
                        {
                            sw.Write(ex);
                        }
                        catch (Exception ex1)
                        {
                            WriteLog(ex1);
                        }
                        finally
                        {
                            sw.Close();
                            fs.Close();
                        }
                    }
                }
            }
            else
            {
                using (FileStream fs = new FileStream(logUrl, FileMode.CreateNew))
                {
                    using (StreamWriter sw = new StreamWriter(fs, Encoding.Default))
                    {
                        try
                        {
                            sw.Write(ex);
                        }
                        catch (Exception ex1)
                        {
                            WriteLog(ex1);
                        }
                        finally
                        {
                            sw.Close();
                            fs.Close();
                        }
                    }
                }
            }
        }
        //Select the wsp file action.
        private void select_wsp_button_Click(object sender, EventArgs e)
        {
            OpenFileDialog wspFile = new OpenFileDialog();
            if (wspFile.ShowDialog() == DialogResult.OK) 
            {
                WspText.Text = wspFile.FileName;
            }
        }
        //Retract and deploy action.
        private void ok_button_Click(object sender, EventArgs e)
        {
            //1.Login site and deactive the feature.
            IWebDriver iw = new InternetExplorerDriver();
            iw = login(iw, SiteComBox.Text.ToString(), UserNameText.Text.ToString(), PwdText.Text.ToString());
            INavigation navi = iw.Navigate();
            //Go to the site collection features page.
            navi.GoToUrl(SiteComBox.Text.ToString() + "/_layouts/15/ManageFeatures.aspx?Scope=Site");
            //Judge the feature category by the name wsp file selected.
            string category;
            var wspPath = WspText.Text.ToString().Split(new Char[] { '\\' });
            category = wspPath[wspPath.Count() - 1];
            //MessageBox.Show(category.ToString());
            //Deactive the feature.
            deactivateFeature(iw, category);
            //2.If has solution, retract first.
            string solutionPageUrl = "http://wdsinpexca:10000/_admin/Solutions.aspx";
            navi.GoToUrl(solutionPageUrl);
            iw.FindElement(By.LinkText(category.ToLower())).Click();
            waitUntilPageLoaded(iw, "ctl00_PlaceHolderMain_solutionStatusToolBar_RptControls_LinkRetractSolution_LinkText");
            iw.FindElement(By.Id("ctl00_PlaceHolderMain_solutionStatusToolBar_RptControls_LinkRetractSolution_LinkText")).Click();
            waitUntilPageLoaded(iw, "ctl00_PlaceHolderMain_ctl02_RptControls_BtnSubmit");
            iw.FindElement(By.Id("ctl00_PlaceHolderMain_ctl02_RptControls_BtnSubmit")).Click();
            //During the retracting period, there will be a down. Let's sleep to get over it.
            //Thread.Sleep(300000);
            //Back to the wsp page.
            iw.FindElement(By.LinkText(category.ToLower())).Click();
            waitUntilPageLoaded(iw, "ctl00_PlaceHolderMain_solutionStatusToolBar_RptControls_LinkRemoveSolution_LinkText");
            iw.FindElement(By.Id("ctl00_PlaceHolderMain_solutionStatusToolBar_RptControls_LinkRemoveSolution_LinkText")).Click();
            //Click OK in the popup window.
            IntPtr myPtr = GetForegroundWindow();
            if (myPtr != IntPtr.Zero)
            {
                System.Windows.Forms.SendKeys.SendWait("{ENTER}");
            }
            //3.Deploy the solution to the web app.

            //4.Active the site wsp feature.
        }
        //Deactive the feature accourding to the wsp solution category.
        private void deactivateFeature(IWebDriver iw,string category)
        {
            if (category == "APPSSP2013MISite.wsp")
            {
                //Deactive the MISITE feature.
                waitUntilPageLoaded(iw, "ctl00_PlaceHolderMain_featact_rptrFeatureList_ctl21_ctl00_divFeatureStatus");
                string featureStatus = iw.FindElement(By.Id("ctl00_PlaceHolderMain_featact_rptrFeatureList_ctl21_ctl00_divFeatureStatus")).GetAttribute("featurestatus").ToString();
                if (featureStatus == "Active")
                {
                    waitUntilPageLoaded(iw, "ctl00_PlaceHolderMain_featact_rptrFeatureList_ctl21_ctl00_btnActivate");
                    iw.FindElement(By.Id("ctl00_PlaceHolderMain_featact_rptrFeatureList_ctl21_ctl00_btnActivate")).Click();
                    waitUntilPageLoaded(iw, "ctl00_PlaceHolderMain_lnkbtnDeactivate");
                    iw.FindElement(By.Id("ctl00_PlaceHolderMain_lnkbtnDeactivate")).Click();
                }
            }
        }
        //Wait until loaded method.
        private static void waitUntilPageLoaded(IWebDriver iw, string element)
        {
            try
            {
                iw.FindElement(By.Id(element));
            }
            catch (Exception ex)
            {
                WriteLog(ex);
                //Refresh the current page.
                //iw.Navigate().Refresh();
                Thread.Sleep(1000);
                waitUntilPageLoaded(iw, element);
            }
        }
        //Login SP site method.
        public static IWebDriver login(IWebDriver driver, string url,string userName,string pwd)
        {
            INavigation navigation = driver.Navigate();
            navigation.GoToUrl(url);
            //driver.FindElement(By.Id("overridelink")).Click();
            IntPtr myPtr = GetForegroundWindow();
            //IntPtr hWnd = FindWindow(null, "abc");
            if (myPtr != IntPtr.Zero)
            {
                //Send message to the window.
                System.Windows.Forms.SendKeys.SendWait(userName);
                System.Windows.Forms.SendKeys.SendWait("{TAB}");
                System.Windows.Forms.SendKeys.SendWait(pwd);
                System.Windows.Forms.SendKeys.SendWait("{ENTER}");
            }
            return driver;
        }
    }
}
天外归云的主页 天外归云 | 菜鸟二级 | 园豆:368
提问于:2015-08-24 18:26
< >
分享
其他回答(5)
0

大概意思就是说CLR在60秒内都没能往下走,然后这线程又占着资源还在很长时间的运行过程中没有window消息。这种状态有可能是性能很低下且应用没有响应的情况下还去追加使用内存导致的。为了避免这个问题,对所有单线程单元(STA)线程,你必须长时间运行的操作过程中泵周期消息。

 

总的来说好像是系统觉得你的程序挂掉了所以提示你一下吧。。。

小白菜T | 园豆:564 (小虾三级) | 2015-08-24 19:54

唉,不知道症结所在啊……

支持(0) 反对(0) 天外归云 | 园豆:368 (菜鸟二级) | 2015-08-25 08:56
0

不懂,帮顶。

jackccc | 园豆:1341 (小虾三级) | 2015-08-25 10:26

谢谢……T.T

支持(0) 反对(0) 天外归云 | 园豆:368 (菜鸟二级) | 2015-08-25 10:28
0

乱码了吧

顾星河 | 园豆:7169 (大侠五级) | 2015-08-25 10:37

不是啊。

支持(0) 反对(0) 天外归云 | 园豆:368 (菜鸟二级) | 2015-08-25 11:01
0

用啥不好非用日文版的我也是醉了

羽商宫 | 园豆:2490 (老鸟四级) | 2015-08-25 10:45

是操作系统是日语的,没办法……环境就是这样的……我也不想。

支持(0) 反对(0) 天外归云 | 园豆:368 (菜鸟二级) | 2015-08-25 11:01
0

这...还以为楼主喜欢日语呢,SP没接触过...加相关的群问问

LovingNow | 园豆:132 (初学一级) | 2015-08-25 13:09

也许和SP确实关系……

支持(0) 反对(0) 天外归云 | 园豆:368 (菜鸟二级) | 2015-08-25 13:26
1

日文的异常提示看不太懂, 不过感觉是你等待的那个事件需要在主线程(UI线程)上执行, 然后你的等待是从OnClick事件发起的也在主线程上执行并且占着不放

解决方法就是另起一个新的线程来等待

收获园豆:5
逸风之狐 | 园豆:360 (菜鸟二级) | 2015-08-28 15:58

兄弟!能否给个代码意思意思,我就要离职了,也许没有机会试了。

支持(0) 反对(0) 天外归云 | 园豆:368 (菜鸟二级) | 2015-08-28 16:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册