C# 葡萄藤3.1-';进程无法访问文件';

C# 葡萄藤3.1-';进程无法访问文件';,c#,.net,grapevine,C#,.net,Grapevine,我有一个解决方案,它利用葡萄藤在程序类中启动服务器。 但由于某种原因,只要我启动程序,调用server.start()时程序就会崩溃。 目前还没有解决方案的其他部分在运行,所以我不知道这是如何发生的 在Windows 10上以管理员身份在Visual Studio 15中运行 Program.cs using System; using System.Threading; using Grapevine.Server; using QuantConnect.Logging; namespace

我有一个解决方案,它利用葡萄藤在
程序
类中启动服务器。 但由于某种原因,只要我启动程序,调用
server.start()
时程序就会崩溃。 目前还没有解决方案的其他部分在运行,所以我不知道这是如何发生的

在Windows 10上以管理员身份在Visual Studio 15中运行

Program.cs

using System;
using System.Threading;
using Grapevine.Server;
using QuantConnect.Logging;

namespace QuantConnect.Services
{
    class Program
    {
        /// <summary>
        /// QuantConnect C# Services Server:
        /// </summary>
        static void Main(string[] args)
        {
            var server = new RESTServer
            {
                //Host = Configuration.Config.Get("grapevine-host"),
                //Port = Configuration.Config.Get("grapevine-port")
                Host = Configuration.Config.Get("grapevine-host", "localhost"),
                Port = Configuration.Config.Get("grapevine-port", "80")
            };

            Log.Trace(string.Format("Starting Server On {0}:{1}", server.Host, server.Port));
            server.Start(); // Exception occurs here

            while (server.IsListening)
            {
                Thread.Sleep(300);
            }

            Log.Trace("Server stopped. Press key to continue...");
            Console.ReadLine();
        }
    }
}

所以我明白了问题所在。 我将Grapevine设置为使用端口
80

Port=Configuration.Config.Get(“葡萄藤端口”,“80”)

问题是,我的机器上有另一个使用此端口的服务,我将其更改为使用
8080
,现在它工作正常


Port=Configuration.Config.Get(“grapevine端口”,“8080”)

虽然这根本无法解决您的问题,但我建议您更新到grapevine 4.x的最新版本。好东西!谢谢你使用小道消息。嗨,斯科特,问题是我必须使用3.1。就在这个场景中,我的手
System.Net.HttpListenerException was unhandled
  ErrorCode=32
  HResult=-2147467259
  Message=The process cannot access the file because it is being used by another process
  NativeErrorCode=32
  Source=System
  StackTrace:
       at System.Net.HttpListener.AddAllPrefixes()
       at System.Net.HttpListener.Start()
       at Grapevine.Server.RESTServer.Start()
       at QuantConnect.Services.Program.Main(String[] args) in C:\Users\RichardsPC\Source\Repos\Lean\Services\Program.cs:line 29
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: