با 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();