private void OpenListening() { Task.Run(() => { try { // create msg handle assembly var allFile = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory) .Where(o => System.IO.Path.GetExtension(o) == ".dll"); foreach (var file in allFile) { var type = Assembly.LoadFrom(file).GetTypes() .FirstOrDefault(o => o != typeof(IWXMsgHandle) && typeof(IWXMsgHandle).IsAssignableFrom(o)); if (type == null) { continue; } _wxSerivice.MsgHandle = Activator.CreateInstance(type) as IWXMsgHandle; break; } // begin Listen the msg _wxSerivice.Listening(ListeningHandle); } catch (LoginOutException) { MessageBox.Show("在其它地方登录!程序将退出!"); Environment.Exit(0); } catch (Exception e) { Console.WriteLine("OpenListening: " + e.Message); } }); }