public async Task Run() { try { if (await WaitForBrowserConnect() == false) { return; } _ipcService = new IpcService(this); while (true) { try { var response = await _host.Read <BrowserMessage>(); await ProcessMessage(response); } catch (JsonSerializationException jsonEx) { LogTo.Error(jsonEx, "Invalid message received"); } } } catch (EndOfStreamException) { OnBrowserDisconnected(); } catch (Exception ex) { LogTo.Error(ex, "An exception occurred in the Run() loop"); } }
private static async Task Main(string[] args) { var host = new NativeMessagingHost(); try { while (true) { var response = await host.Read <Message>(); // Echo response await host.Write(new Message($"You said {response.Value} at {response.DateTime}")); } } catch (EndOfStreamException) { // Disconnected } catch (Exception exception) { await host.Write(new Message($"Error: {exception}")); Console.WriteLine($"Oh 💩: {exception}"); Environment.FailFast("Oh 💩", exception); } }
static async Task Main(string[] args) { var host = new NativeMessagingHost(); try { await host.Read <dynamic>(); await host.Write(new { hostName = $"{Environment.MachineName}" }); } catch (Exception exception) { await host.Write(new { error = $"{exception}" }); } }