Some NGit materials prevent C # application from closing properly

I am trying to use NGit library in my application (C #, MS.NET 4.0). Since we are on the MS platform, I rebuilt NGit for the .NET Framework 4.0 under VS 2010. Most of the things are good and all the functionality works well, but the application freezes when it is finished. VS Debugger shows that some stream from Sharpen lib is infinitely in a waiting state, and no one signals a shutdown. This happens when I use any of the class instance methods NGit.Api.Git(for static methods everything seems OK). Has anyone encountered such problems? Any suggestions?

Example code using the class Git:

Git myrepo = Git.Init().SetDirectory(@"C:\myrepo.git").SetBare(true).Call();
FetchResult fetchResult = myrepo.Fetch()
    .SetProgressMonitor(new TextProgressMonitor())
    .SetRemote(@"C:\projects\initialrepo")
    .SetRefSpecs(new RefSpec("refs/heads/master:refs/heads/master"))
    .Call();
//
// Some other work...
//
myrepo.GetRepository().Close();

And here is the place where the thread hangs:

Sharpen.ThreadExecutor, 9 (St.Monitor.Wait (pendingTasks)):

public void RunPoolThread ()
{
    while (!IsTerminated ()) {
        try {
            Runnable r = null;
            lock (pendingTasks) {
                freeThreads++;
                while (!IsTerminated () && pendingTasks.Count == 0)
                    ST.Monitor.Wait (pendingTasks);
                if (IsTerminated ())
                    break;
                r = pendingTasks.Dequeue ();
            }
            if (r != null)
                r.Run ();
        }
        catch (ST.ThreadAbortException) {
            ST.Thread.ResetAbort ();
        }
        catch {
        }
    }
}
+3
1

. , . , .

: https://github.com/slluis/ngit/issues/8

, ,


  • Linux (Mono 2.6.7,.NET 3.5)
  • Linux (Mono 2.11,.NET 4.0)

, BatchingProgressMonitor ( , TextProgressMonitor) "", , alarmQueue Shutdown.

BatchingProgressMonitor:

public static void ShutdownNow()
{
    alarmQueue.ShutdownNow();
}

"", BatchingProgressMonitor.ShutdownNow() . WorkedForMe TM. , , #if/#endif.

.

using System;
using NGit;
using NGit.Api;
using NGit.Transport;

namespace Stacko
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Git myrepo = Git.Init().SetDirectory(@"/tmp/myrepo.git").SetBare(true).Call();
            {
                var fetchResult = myrepo.Fetch()
                    .SetProgressMonitor(new TextProgressMonitor())
                    .SetRemote(@"/tmp/initial")
                    .SetRefSpecs(new RefSpec("refs/heads/master:refs/heads/master"))
                    .Call();
                //
                // Some other work...
                //
                myrepo.GetRepository().Close();
            }
            System.GC.Collect();

#if false
            System.Console.WriteLine("Killing");
            BatchingProgressMonitor.ShutdownNow();
#endif
            System.Console.WriteLine("Done");

        }
    }
}

-. :

Cheers,

+3

All Articles