1
Vote

Addin Integration is unstable

description

The tool is great for jslinting.
 
Setup:
VS 2008 SP 1
Windows XP SP2
ASP.NET Website
 
Files copied to:
C:\Documents and Settings\<<user>>\My Documents\Visual Studio 2008\Addins
 
Current situation:
The addin works every now and then.
Integrate into solution does not catch every time.
 
What can I do to ensure that it is part of the build every time?

comments

bkadam wrote Feb 4, 2010 at 8:00 AM

I've had the same problem. There appears to be a timing problem when cscript is run (routine PerformCheck). I've not discovered why, but a (bad) workaround is to run that part of the code twice.
//temp: do twice, there is some timing problem
        for (int l_i_i = 0; l_i_i < 2; l_i_i++)
        {
            try
            {
                p.Start();

                ThreadPool.QueueUserWorkItem(new WaitCallback(ReadProcessStream), p.StandardError);

                // Wait for process to finish, and kill if it's not finished in predefined time
                bool finished = p.WaitForExit(waitTime * 1000);
                if (!finished)
                {
                    p.Kill();
                    List<string[]> ret = new List<string[]>();
                    ret.Add(new string[] {"0", "", string.Format("JSLint.VS failed to finish processing in {0} seconds", waitTime),
                    "0", "0", "0", "0" });
                    return ret;
                }
            }
            finally
            {
                p.Close();
            }
        }

bkadam wrote Feb 4, 2010 at 9:00 AM

Found the cause of the problem: ReadProcessStream is not ready when the array errors is created in PerformCheck. This does the trick:

... (ThreadPool etc. in PerformCheck)
        finally, see above
        {
            p.Close();
        }
        if (!Monitor.TryEnter(_processResults, 1000))
        {
            //the processresults are not ready!
            List<string[]> ret = new List<string[]>();
            ret.Add(new string[] {"0", "", string.Format("JSLint.VS failed to finish processing in {0} seconds", waitTime),
                    "0", "0", "0", "0" });
            return ret;
        }

bkadam wrote Feb 4, 2010 at 9:59 AM

Of course, when the TryEnter succeeds, it must release _processresults again.
Oops, sorry about that!
finally
        {
            p.Close();
        }
        if (!Monitor.TryEnter(_processResults, 1000))
        {
            //the processresults are not ready!
            List<string[]> ret = new List<string[]>();
            ret.Add(new string[] {"0", "", string.Format("JSLint.VS failed to finish processing in {0} seconds", waitTime),
                    "0", "0", "0", "0" });
            return ret;
        }
        else
        {
            Monitor.Exit(_processResults);
        }

bkadam wrote Feb 4, 2010 at 12:13 PM

There is another error in the code: ReadProcessStream locks on _processResults, which is of value type string. This approach fails when Monitor.TryEnter and Monitor.Exit are used, see msdn Threading/Monitor. Therefore, _processResults should be wrapped in an object to ensure the Monitor function to work properly. And it does.

wrote Feb 13, 2013 at 9:31 PM