-1

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();
    }  
}
}
  • Have you tried debugging.. also have you tried googling how to open and close a splash screen using WPF.? or WinForms there are several working examples on `SO` as well http://stackoverflow.com/questions/48916/multi-threaded-splash-screen-in-c – MethodMan Jan 25 '15 at 22:08
  • i try debugging and also searching on the net also youtube and i also found some similar case but it dont work in my case and i cant fix my problem. – forbiddenboy Jan 25 '15 at 22:11
  • You don't have any code here that would close the "splash" window, so not much of a surprise that it doesn't close. There's nothing in the code you posted that would explain the `MainWindow` being shown more than once. I wouldn't implement a splash screen this way in the first place, but one thing that looks particularly wrong to me is that the call to `InitializeComponent()` really should be the _first_ thing in your constructor, not the last. Please fix your question so that it includes [a good, minimal, complete code example](http://stackoverflow.com/help/mcve) – Peter Duniho Jan 26 '15 at 04:14

1 Answers1

0

there is a problem with code that i cant close the form caz i chose a page not a form. i must make new windows for that the following code is false

 public partial class splash : Page
 {
  .......
 }

this is the form:

 public partial class splash : Form
 {
  .......
 }