View Full Version : سوال: اسپلش اسکرین و لودینگ واقعی WPF
amin_amz
جمعه 07 اردیبهشت 1397, 13:45 عصر
با سلام خدمات همه ی کاربران برنامه نویس.
من پروژه WPFی رو دارم مینویسم که در زمان اجرای نرم افزار بررسی کنه که ارتباط با پایگاه داده برقرار هست یا نه و درصورت وجود مشکل خطایی نمایش بده و یا در صورت وصل نبودن دیتابیس اونو اتچ کنه . انجام این کار ها زمانی رو میگیره من میخوام اسپلش اسکرینی بسازم که روی اون لودینگی داشته باشه که زمان انتظار واقعی رو به کاربر نشون بده.لطفا اگر میشه راهنماییمم کنید.
کدهای بررسی رو در Window_Initialize صفحه اصلی نوشتم
رامین مرادی
شنبه 08 اردیبهشت 1397, 11:21 صبح
با wpf کار نکردم. اما میتونید با این کدها یه فرم رو به صورت بک گراند ورکر اجرا کنید و مثلا به کاربر یه لودینگ رو نشون بدید و بعد از اتمام اتصال اون لودینگ رو ببندید.
یه فرم ایجاد کنید و کدهای زیر رو توش کپی کنید.البته محتوای این فرم رو هم به سلیقه خودتون طراحی کنید مثلا چرخش یه پروگرس بار زیبا
private static Thread _LoadingScreenThread;
private static Wait _ls;
private static bool _shown = false;
private static Form _parent;
public static void ShowLoadingScreen(Form parent)
{
_parent = parent;
if (_LoadingScreenThread == null)
{
_LoadingScreenThread = new Thread(new ThreadStart(DoShowLoadingScreen));
_LoadingScreenThread.SetApartmentState(ApartmentSt ate.STA);
_LoadingScreenThread.IsBackground = true;
_LoadingScreenThread.Start();
}
}
public static void CloseLoadingScreen()
{
System.Threading.Thread.Sleep(250);
if (_ls != null && _ls.InvokeRequired)
{
_ls.Invoke(new MethodInvoker(CloseLoadingScreen));
}
else
{
if (_shown)
{
_shown = false;
Application.ExitThread();
}
if (_LoadingScreenThread != null) _LoadingScreenThread.Interrupt();
try
{
_ls.Close();
_ls.Dispose();
}
catch
{}
_LoadingScreenThread = null;
}
}
private static void DoShowLoadingScreen()
{
_ls = new Wait();
//_ls.Wait_Progress.IsRunning = true;
_ls.ShowDialog();
}
private void Wait_Load(object sender, EventArgs e)
{
this.Activate();
}
و نحوه استفادش هم به این صورته:
Wait.ShowLoadingScreen(this);
//کدهای شما
Wait.CloseLoadingScreen();
this.Activate();
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.