im new in WPF and trying to have splash screen with progress bar i make it but i have 2 problems here first is when my progress bar end the main window open repetitive :(.and the second problem is i cant close the current window. thx for healping
using System.Threading;
using System.Windows.Controls;
using System.Windows.Threading;
namespace pro_karimian_
{
/// <summary>
/// Interaction logic for splash.xaml
/// </summary>
public partial class splash : Page
{
private double progcount = 0,endit = 1;
public splash()
{
new Thread(
delegate()
{
somefun();
if(progcount == endit)
{
//then close The window
}
}).Start();
InitializeComponent();
}
private void somefun()
{
for (int i = 0; i < 10; i++)
{
Thread.Sleep(100);
Dispatcher.BeginInvoke(DispatcherPriority.Background, (SendOrPostCallback)delegate { progbar.SetValue(ProgressBar.ValueProperty, progcount); }, null);
progcount += 0.1;
}
endit = progcount;
Thread th = new Thread(
delegate()
{
MainWindow go = new MainWindow();
go.ShowDialog();
});
th.ApartmentState = ApartmentState.STA;
th.Start();
}
}
}