Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApplication4
- {
- using System.Windows.Forms;
- class Program
- {
- static void Main(string[] args)
- {
- Application.Run(new DemoView());
- }
- }
- }
- namespace ConsoleApplication4
- {
- public interface IDemoView
- {
- void SetProgress(int val);
- }
- }
- namespace ConsoleApplication4
- {
- public interface IDemoPresenter
- {
- void OnButtonClick();
- }
- }
- namespace ConsoleApplication4
- {
- using System;
- public interface IDemoModel
- {
- void DoWork(Action<int> progressCallback);
- }
- }
- namespace ConsoleApplication4
- {
- using System;
- using System.Windows.Forms;
- public partial class DemoView : Form, IDemoView
- {
- private IDemoPresenter _presenter;
- public DemoView()
- {
- _presenter = new DemoPresenter(this, new DemoModel());
- InitializeComponent();
- }
- public void SetProgress(int val)
- {
- Invoke(new EventHandler((s, e) => { progressBar1.Value = val; }));
- }
- private void button1_Click(object sender, EventArgs e)
- {
- _presenter.OnButtonClick();
- }
- }
- }
- namespace ConsoleApplication4
- {
- public class DemoPresenter : IDemoPresenter
- {
- private IDemoView _view;
- private IDemoModel _model;
- public DemoPresenter(IDemoView view, IDemoModel model)
- {
- _view = view;
- _model = model;
- }
- public void OnButtonClick()
- {
- _model.DoWork(_view.SetProgress);
- }
- }
- }
- namespace ConsoleApplication4
- {
- using System;
- using System.Linq;
- using System.Threading;
- public class DemoModel : IDemoModel
- {
- public void DoWork(Action<int> progressCallback)
- {
- new Thread(() =>
- {
- foreach (var el in Enumerable.Range(0, 101))
- {
- progressCallback(el);
- Thread.Sleep(100);
- }
- }).Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment