PDA

View Full Version : سوال: معادل کد (ساده)



cmsdqq2
شنبه 21 آذر 1394, 08:30 صبح
بنده این کد رو برای نمایش فرم لطفا منتظر بمانید رو اجرا کردم، برنامه هم اجرا میشه و فرم هم نمایش داده میشه اما بعد از چند ثانیه مشخص هنگ میکنه. خود برنامه هم مشکلی نداره





public partial class popup : MetroWindow
{




public popup()
{
InitializeComponent();
}


private static Thread _LoadingScreenThread;
private static popup _ls;
private static bool _shown = false;






public static void ShowLoadingScreen()
{


if (_LoadingScreenThread == null)
{
_LoadingScreenThread = new Thread(new ThreadStart(DoShowLoadingScreen));
_LoadingScreenThread.SetApartmentState(ApartmentSt ate.STA);
_LoadingScreenThread.IsBackground = true;
_LoadingScreenThread.Start();
}
}






private static void DoShowLoadingScreen()
{
_ls = new popup();
_ls.Media.IsEnabled = true;
_ls.ShowDialog();
}




public static void CloseLoadingScreen()
{
System.Threading.Thread.Sleep(250);
if (_ls != null)
{
_ls.Dispatcher.Invoke(new Action(CloseLoadingScreen));
}
else
{
if (_shown)
{
_shown = false;
// Dispatcher.CurrentDispatcher.Thread.Abort();
Application.Current.Dispatcher.Invoke(CloseLoading Screen);
}
if (_LoadingScreenThread != null) _LoadingScreenThread.Interrupt();


try
{
_ls.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());


}


_LoadingScreenThread = null;
}
}




}