How to transfer value from one window to another

@Ruri I have two windows. One is the main window, and the other is a setting window. In the setting window, I’m getting threads number from the user. How can I get those threads number from the setting window to the main window so I can show the number of threads in the main window?
I forgot to mention I’m using WPF and the language is C#

You would use public static ints or public static strings.

Inside of your settings windows .xaml.cs you would want to create something like this

(Note: I did this process backwards of what you want. I have the main window set threads and the settings window displays it. You want it the opposite way.

Inside the window, you want to display the value you set. You can do it this way, or just call the value when you want.

Here is the settings window with a label that displays the thread value set in the main window.


example of the little wpf form I made for it

1 Like

Thanks, I got your point, and actually, it’s working. I just wanted to ask if there is another approach like binding.

Not sure about binding. Constructors work too though!

Main window with a text box for threads

and the settings page that displays thread value

Although with WPF, I don’t recommend creating a new window for every page.

It’s a lot easier to work with data if you use Tab controllers.

@Pure Thanks for the suggestion. I’ll keep that in mind and again thanks for your effort

@Pure are you aware of Rurilib.Parallizatoin? If yes can you tell me what is the best place to call parallizer.CPM either in onResult or inside parallizer itself?

I would do it via a Timer object, since CPM should be updated every second or so to properly reflect changes.

1 Like

@Ruri can u tell me the file name where I can find this piece of code updating cpm in timer

Look right about here

1 Like

@Ruri, I did it this way. Is it ok?

updateTicker = new Timer(new TimerCallback(_ => calculateCPM()), null, 1000, 1000);

I’m calling it onStart button
and on stop and abort I’m disposing updateTicker
and on resume, I’m again calling the above one