forked from 47-studio-org/PostSharp.Samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainWindow.xaml.cs
52 lines (45 loc) · 999 Bytes
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using PostSharp.Patterns.Threading;
using System;
using System.Windows;
namespace PostSharp.Samples.Threading.ThreadDispatching
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void startButton_Click(object sender, RoutedEventArgs e)
{
EnableControls(false);
DoStuff();
}
[Background]
private void DoStuff()
{
var random = new Random();
for (var i = 0; i <= 100; i++)
{
for (var j = 0; j < 1000000; j++)
{
Math.Sin(random.NextDouble());
}
SetProgress(i);
}
EnableControls(true);
}
[Dispatched(true)]
private void SetProgress(int progress)
{
progressBar.Value = progress;
}
[Dispatched(true)]
private void EnableControls(bool enabled)
{
startButton.IsEnabled = enabled;
}
}
}