Witam,stworzyłem sobie SplashScreen z progress barem który bez zarzutu ładuję się do 100% i chciałbym,żeby po wykonaniu tej czynności okno się zamknęło jednakże gdy próbuję pod pętle for lub do niej wrzucić polecenie
SplashScreen1.Close();
to otrzymuję błędy.
Tu jest całość kodu
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;
using System.ComponentModel;
namespace RPad_2014_Ultimate
{
/// <summary>
/// Interaction logic for SplashScreen.xaml
/// </summary>
public partial class SplashScreen : Window
{
public SplashScreen()
{
InitializeComponent();
}
private void SplashScreen1_ContentRendered_1(object sender, EventArgs e)
{
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.DoWork += worker_DoWork;
worker.ProgressChanged += worker_ProgressChanged;
worker.RunWorkerAsync();
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i < 100; i++)
{
(sender as BackgroundWorker).ReportProgress(i);
Thread.Sleep(100);
}
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
PG1.Value = e.ProgressPercentage;
}
}
}