Example #1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            _logger.LogInformation("Show");
            var form = await _formProvider.GetFormAsync <Form2>();

            form.Show();
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            int count = 0;

            while (!stoppingToken.IsCancellationRequested)
            {
                await Task.Delay(5000, stoppingToken);

                if (count < 5)
                {
                    // Fetch the form here using IFormProvider
                    // The form provider will get the form from the DI container on the gui thread
                    // Then we must invoke the Show method on the gui thread as well using IGuiContext
                    _logger.LogInformation($"GetFormAsync {Thread.CurrentThread.ManagedThreadId} {Thread.CurrentThread.Name}");
                    var form = await _fp.GetFormAsync <Form2>();

                    _guiContext.Invoke(() => form.Show());
                }
                count++;
            }
        }