question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't find any way to change the state of the screen programatically

See original GitHub issue

I have the following code:

using Terminal.Gui;

namespace TestConsole
{
    public class App : Window
    {
        private Label _label;
        public App() : base("Test Screen")
        {
            X = 0;
            Y = 0;
            Width = Dim.Fill();
            Height = Dim.Fill();
            _label = new Label("this is a label")
            {
                X = 0,
                Y = 0,
                Width = Dim.Fill(),
            };
            this.Add(_label);
        }
        public void SetNewText(string newText)
        {
            Application.MainLoop.Invoke(() =>
            {
                _label.Text = newText;
            });
        }
    }
    class Program
    {
        static void Main()
        {
            Application.Init();
            App _consoleApp = new App();
            var runToken = Application.Begin(_consoleApp);
            Application.RunLoop(runToken);
            _consoleApp.SetNewText("this is a new text");
            Application.End(runToken);
        }
    }
}

The point is to open a screen, and later on, depending on some further processes, I want to update what’s on the screen. But whatever I try doesn’t work. What is done wrong in my example?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
paillavecommented, Mar 3, 2020

ok, I searched yesterday for ages with no solution, but it seems I simply was in lack of inspiration. Here is how the App class should be used:

    class Program
    {
        static void Main()
        {
            Application.Init();
            App _consoleApp = new App();
            using (Application.RunState runToken = Application.Begin(_consoleApp))
            {
                Task.Run(() => Application.RunLoop(runToken));
                _consoleApp.SetNewText("this is a new text");
                Thread.Sleep(5000);
            }
        }
    }
0reactions
BDispcommented, Mar 3, 2020

Put also “Thread.Sleep(5000);” before “_consoleApp.SetNewText(“this is a new text”);” and you’ll see the old label text before changed to the new one!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change screen orientation in Android without reloading the ...
I want to change the orientation programmatically while running my Android App, with these lines of code: setRequestedOrientation(ActivityInfo.
Read more >
Interact programmatically with the Navigation component
The Navigation component provides ways to programmatically create and interact with certain navigation elements. Create a NavHostFragment.
Read more >
How to change the language on Android at runtime and ...
The first place is your “Settings” screen or whatever place you use to change the language in your application. Note that after the...
Read more >
How do I make a figure full screen programmatically in ...
Starting in MATLAB R2018a, you can use the "WindowState" property to maximize, minimize, or display a figure in full-screen mode.
Read more >
Debugging Flutter apps programmatically
This doc describes debugging features that you can enable in code. For a full list of debugging and profiling tools, see the Debugging...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found