/*
Task.Run(async () =>
{
}
*/
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace VisualSnake
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
static Random rnd = new Random();
public MainWindow()
{
InitializeComponent();
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);
}
}
}
Rectangle rect = new Rectangle
{
Stroke = Brushes.LightBlue,
StrokeThickness = 2,
Width = 20,
Height = 20
};
Canvas.SetLeft(rect, 25);
Canvas.SetTop(rect, 25);
canv_01.Children.Add(rect);
Rectangle rectangle = new Rectangle();
rectangle.X = 20;
rectangle.Y = 20;
rectangle.Width = TBasicConstants.getBasicSizeOfBlock();
rectangle.Height = TBasicConstants.getBasicSizeOfBlock();
PaintEventArgs e = new PaintEventArgs( ... ??? ... , rectangle);