/// <summary> /// Named pipe server /// </summary> /// <param name="aNewMessage"></param> public static void Server(NewMessageDelegate aNewMessage) { // Just keep trying to connect (in the background). new System.Threading.Thread(new System.Threading.ThreadStart(delegate() { Thread(aNewMessage); })) { Name = Program.PipeServerThreadName, IsBackground = true } .Start(); }
public static void begin(string inPipeName, NewMessageDelegate inDelegate) { pipeName = inPipeName; pipeServerListener = new PipeListener(); pipeServerListener.PipeMessage += inDelegate; pipeServerListener.Listen(); connected = false; }
protected virtual void OnNewMessage(MessageLogModel message) { NewMessageDelegate handler = NewMessage; if (handler != null) { handler(message); } }
public static bool Open(NewMessageDelegate msg) { if (_BtListener == null) { _BtListener = new BluetoothListener(BT_GUID); } _BtListener.Stop(); _BtListener.Start(); _Listen = true; _BtListener.BeginAcceptBluetoothClient(ListenThread, null); return true; }
public LongPollListener(VkApi vkApi, EditMessageDelegate editMessage = null, FriendBecameOfflineDelegate friendBecameOffline = null, FriendBecameOnlineDelegate friendBecameOnline = null, NewMessageDelegate newMessage = null, ReadAllIncomingMessagesDelegate readAllIncomingMessages = null, ReadAllOutcomingMessagesDelegate readAllOutcomingMessages = null, UserTypingInPrivateDialogDelegate userTypingInPrivateDialog = null ) { _vkApi = vkApi; _newMessage = newMessage; _editMessage = editMessage; _friendBecameOffline = friendBecameOffline; _friendBecameOnline = friendBecameOnline; _readAllIncomingMessages = readAllIncomingMessages; _readAllOutcomingMessages = readAllOutcomingMessages; _userTypingInPrivateDialog = userTypingInPrivateDialog; }
/// <summary> /// The server thread /// </summary> /// <param name="aNewMessage"></param> private static void Thread(NewMessageDelegate aNewMessage) { while (true) { using (Utility.NamedPipeServerStream PipeStream = new Utility.NamedPipeServerStream( Program.PipeBaseName, Utility.User.UserName, System.IO.Pipes.PipeDirection.In)) { // Try to connect Debug.WriteLine("Advertising with in-pipe:" + PipeStream.Name); try { PipeStream.Server.WaitForConnection(); } catch (Exception Ex) { Debug.WriteLine(Ex); // Do something?? } Debug.WriteLine("Connected = " + PipeStream.Server.IsConnected.ToString()); // Just keep on reading using (System.IO.StreamReader Reader = new System.IO.StreamReader(PipeStream.Server)) while (PipeStream.Server.IsConnected) { while (PipeStream.Server.IsConnected) { try { string In = Reader.ReadLine(); if (In != null && aNewMessage != null) aNewMessage(In); Debug.WriteIf(In == null, '+'); } catch (Exception Ex) { Debug.WriteLine(Ex); } } } PipeStream.Server.Close(); // Close up and wait for next one } } }
public static void dispose(NewMessageDelegate inDelegate) { pipeServerListener.PipeMessage -= inDelegate; pipeServerListener = null; }