我写了一个类库程序来当window服务的服务核心、一个控制台程序来启动服务,但是启动之后就出现上面的错误,不明白是什么,请各位帮忙看一下,万分感谢啊!!!!!!!
这是window服务核心代码:
namespace Wrox
{
public class QuoteServer
{
private TcpListener listener;
private int port;
private string filename;
private List<string> quotes;
private Random random;
private Task listenerTask;
public QuoteServer()
: this("F:\\我的桌面\\C#\\ConsoleApplication26\\ConsoleApplication26\\bin\\Debug\\quote.txt")
{
}
public QuoteServer(string filename) : this(filename,7890)
{
}
public QuoteServer(string filename, int port)
{
Contract.Requires<ArgumentNullException>(filename != null);
Contract.Requires<ArgumentException>(port >= IPEndPoint.MinPort && port <= IPEndPoint.MaxPort);
this.filename = filename;
this.port = port;
}
protected void ReadQuotes()
{
try
{
quotes = File.ReadLines(filename).ToList();
if (quotes.Count == 0)
{
//throw new QuoteException("quotes file is empty");
}
random = new Random();
}
catch (IOException ex)
{
//throw new QuoteException("I/O Error", ex);
}
}
protected string GetRandomQuoteofTheDay()
{
int index = random.Next(0, quotes.Count);
return quotes[index];
}
public void Start()
{
ReadQuotes();
listenerTask = Task.Factory.StartNew(Listener, TaskCreationOptions.LongRunning);
}
protected void Listener()
{
try
{
IPAddress ipAddress = IPAddress.Any;
listener = new TcpListener(ipAddress, port);
listener.Start();
while (true)
{
Socket clientSocket = listener.AcceptSocket();
string message = GetRandomQuoteofTheDay();
var encoder = new UnicodeEncoding();
byte[] buffer = encoder.GetBytes(message);
clientSocket.Send(buffer, buffer.Length, 0);
clientSocket.Close();
}
}
catch (SocketException ex)
{
Trace.TraceError(String.Format("QuoteServer {0}", ex.Message));
//throw new QuoteException("socket error", ex);
}
}
public void stop()
{
listener.Stop();
}
public void Suspend()
{
listener.Stop();
}
public void Resume()
{
Start();
}
public void RefreshQuotes()
{
ReadQuotes();
}
}
}
这是控制台代码:
namespace ConsoleApplication26
{
class Program
{
static void Main(string[] args)
{
var qs = new Wrox.QuoteServer("F:\\我的桌面\\C#\\ConsoleApplication26\\ConsoleApplication26\\bin\\Debug\\quote.txt", 4567);
qs.Start();
Console.Write("成功");
Console.ReadLine();
qs.stop();
}
}
}
这个问题提示已经说得很清楚了