Exemple #1
0
        public override Task StartReceiving()
        {
            consumer    = new AnalogyMessageConsumer(UserSettingsManager.UserSettings.Settings.GRPCAddress);
            cts         = new CancellationTokenSource();
            hostingTask = Task.Factory.StartNew(async() =>
            {
                try
                {
#if NETCOREAPP3_1 || NET
                    var token = cts.Token;
                    await foreach (var message in consumer.GetMessages().WithCancellation(token))
                    {
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }

                        MessageReady(this, new AnalogyLogMessageArgs(message, Environment.MachineName, OptionalTitle, Id));
                    }
#else
                    consumer.OnNewMessage += Consumer_OnNewMessage;
#endif
                }
                catch (Exception e)
                {
                    LogManager.Instance.LogError("Error: " + e.Message, nameof(gRPCServerClient));
                }
            });
            return(Task.CompletedTask);
        }
        private async void btnConsumer_Click_1(object sender, EventArgs e)
        {
            if (consuming)
            {
                return;
            }

            consuming           = true;
            btnConsumer.Enabled = false;

            var c = new AnalogyMessageConsumer($"http://{txtIP.Text}");

            await foreach (var m in c.GetMessages().ConfigureAwait(false))
            {
                richTextBox1.Text += Environment.NewLine + m;
            }

            consuming           = false;
            btnConsumer.Enabled = true;
        }