static void Main(string[] args) { string sUserCommand = ""; Console.Title = "OPCClient"; closebtn(); //config初始化 Initialize(); LogFunction.WriteLog(sLogFilePath, "Message:Service Start."); LogFunction.WriteLog(sLogFilePath, "Message:Initialize Compalte."); //Console关闭事件 Console.CancelKeyPress += new ConsoleCancelEventHandler(CloseConsole); //开启OPCClient线程 Action OPCClientaction = new Action(OPCClient); Task threadOPCClient = Task.Run(OPCClientaction); //threadOPCClient.Start(); LogFunction.WriteLog(sLogFilePath, "Message:OPCClient Thread Start."); //开启SqlInsert线程 Action SqlInsertaction = new Action(SqlInsert); Task threadSqlInsert = Task.Run(SqlInsertaction); //threadSqlInsert.Start(); LogFunction.WriteLog(sLogFilePath, "Message:SqlInsert Thread Start."); while (true) { sUserCommand = Console.ReadLine(); if (sUserCommand == "Exit") { if (opcKepClient.opc_connected == true) { opcKepClient.DisConnectServer(); } LogFunction.WriteLog(sLogFilePath, "Message:Service Stop."); break; } } }