Dispatcher.Invoke(
() =>
{
Timer sliderChanger = new Timer(x => {
VideoSlider.Value = VideoPlayer.Position.TotalMilliseconds;
},
null,
0,
1
);
}
);
public Task(Action action, CancellationToken cancellationToken);
public Task(Action action, TaskCreationOptions creationOptions);
public Task(Action<object> action, object state);
public Task(Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions);
public Task(Action<object> action, object state, CancellationToken cancellationToken);
public Task(Action<object> action, object state, TaskCreationOptions creationOptions);
public Task(Action<object> action, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions);
namespace SnakeClasses
{
public class TPoint
{
// Coords of all objects in this project will be indicated by the upper left edge
private Brush pointColor;
private int regardingPointSize;
private int pointCoordX;
private int pointCoordY;
public TPoint(int _x, int _y, int _size, Brush _color)
{
pointColor = _color;
pointCoordX = _x * TBasicConstants.getBasicSizeOfBlock();
pointCoordY = _y * TBasicConstants.getBasicSizeOfBlock();
regardingPointSize = _size * TBasicConstants.getBasicSizeOfBlock();
}
public void drawPoint(Canvas _canvas)
{
Rectangle rect = new Rectangle
{
Fill = pointColor,
Width = regardingPointSize,
Height = regardingPointSize
};
Canvas.SetLeft(rect, pointCoordX);
Canvas.SetTop(rect, pointCoordY);
_canvas.Children.Add(rect);
}
}
}
private async Task drawTPointElement()
{
for (var i = 0; i <= 5; i++)
{
Dispatcher.Invoke(() =>
{
var test = (byte)(i * 10);
Rectangle rectangle = new Rectangle
{
Width = test,
Height = test,
Fill = new SolidColorBrush(Color.FromRgb(test, test, test)),
};
Canvas.SetLeft(rectangle, i * 4);
Canvas.SetTop(rectangle, i * 4);
TestPanel.Children.Add(rectangle);
});
await Task.Delay(TimeSpan.FromSeconds(1));
}
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
void HandleLoaded(object sender, RoutedEventArgs e)
{
Task.Run(async () =>
{
for (int i = 0; i <= 5; i++)
{
TPoint point = new TPoint(5, i, 1, Brushes.Red);
await drawTPointElement(point);
}
});
}
public async Task drawTPointElement(TPoint _rectangle)
{
Canvas.SetLeft(_rectangle.getPoint(), _rectangle.getXCoord());
Canvas.SetTop(_rectangle.getPoint(), _rectangle.getYCoord());
await Task.Delay(1000);
Action action = new Action(() => {
mainCanvas.Children.Add(_rectangle.getPoint());
});
Dispatcher.Invoke(action);
}
}