O
O
oldhowl2015-09-25 15:45:50
.NET
oldhowl, 2015-09-25 15:45:50

MVP how to correctly return a variable in the ViewModel of the progressbar?

Separated form from logic, according to the MVP principle. I want to return a value from the logic to the progressbar.
I press the first time - it does not work.
The second time - it does not work to the end (the thread dies?)
I thought to initialize the variable separately (temp), so as not to access the i memory area, it did not help.
I do 10ms - it works (but I'm not sure what is right)
What am I doing wrong?
Method in Presenter


public void Start()
{
model.Cicle();
SetValProg();
}
public void SetValProg()
{
form.UpdateView(model.progressVal);
}

Method in view
public void UpdateView(int progressBarVal)
{
progressBar1.Value = progressBarVal;
}

9a761cf1a63843f3b64926a2b4eaf4d4.gif

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tex0, 2015-09-25
@tex0

Here
and smoke aside:
- InvokeRequired
- SynchronizationContext
This is a matter of accessing controls from a third-party thread.

S
Stanislav Makarov, 2015-09-25
@Nipheris

Look at the code that regularly reads progressVal from the model and shoves it into the progress bar. In other words, is SetValProg called from where else, except at startup? Personally, I don't see any of the threading issues that tex0 is talking about yet , because from another thread, only the int field of the Model is set.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question