When starting and pressing the button, the window is locked. The meaning of this mini program is to gradually change the color of the button for this, I made a delay in the cycle. Used an anonymous method created via Disspatcer
.
How to block one thread without blocking another? If you do not block, the color will always be the last, that is, yellow. The question is how to display colors with a delay? As I understand my delay option is not correct.
public partial class MainWindow : Window { private delegate void Del(); private Thread _thread; private static Brush _brush; private delegate void dell(); public MainWindow() { InitializeComponent(); } private void Webbtn_Click(object sender, RoutedEventArgs e) { Thread thread = new Thread(ColorsMove); thread.Start(); } private void ColorsMove() { Webbtn.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate { var c = MessageBox.Show("Hello ", "People", MessageBoxButton.OKCancel); if (c == MessageBoxResult.OK) { _brush = Webbtn.Background; var brushesType = typeof (Brushes); // Get all static properties var enumColor = brushesType.GetProperties(BindingFlags.Static | BindingFlags.Public); lock (enumColor) { foreach (var color in enumColor) { this.Background = (SolidColorBrush) color.GetValue(null, null); Thread.Sleep(TimeSpan.FromSeconds(2)); } } } else { Background = _brush; } }); } } }
Thread.Sleep(TimeSpan.FromSeconds(2));
- Vladyslav MatviienkoWPF
, it is very for such purposes and created - Donil