using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace ShutDown
{
public partial class Background : Form
{
public void BackgroundAnimation()
{
this.Opacity = 0.00;
for (double i = 0.00; i < 0.51; i = i + 0.01)
{
this.Opacity = i;
}
}
public Background()
{
InitializeComponent();
// Maximize the window
this.WindowState = FormWindowState.Maximized;
// Animate background
Thread Animation = new Thread(BackgroundAnimation);
Animation.Start();
}
}
}
To kawałek kodu, którym się posługuje. Jednak przy debudowaniu dostaję błąd:
Cross-thread operation not valid: Control 'Background' accessed from a thread other than the thread it was created on.
Jestem początkujący i nie bardzo rozumiem czego chce ode mnie debugger. Przy normalnym wywołaniu funkcji BackgroundAnimation() nie ma problemów, zaś przy używaniu threadingu pojawia się taki komunikat.