如何连续运行进度条,直到DLL未正确加载。 [英] How to run progress bar continuously until DLL not correctly loaded.

查看:78
本文介绍了如何连续运行进度条,直到DLL未正确加载。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在努力解决三天以来的问题。

我在Splash窗口中使用进度条。如果我在一秒钟之后设置等待Task.Delay(1000)我的dll将加载因为程序等待完成延迟时间,那么进度条运行正确。 1秒后,我的进度条停止,我的dll加载。这使程序变得懒惰,并且需要花费很多时间来加载应用程序

我希望两者同时工作。我的进度条应该连续运行并且

我的dll应该在后面运行。之后它会打开登录窗口所以请帮助我

以下是我的代码

我在Xaml创建了进度条。



< ProgressBar Minimum =0Maximum =100Height =10Background =TransparentWidth =100Foreground =BlackName =pbStatusIsIndeterminate =TrueGrid.Column =1保证金=4,29,-4,20/>





我的启动窗口代码在应用程序中。 Xaml.cs

Hi ,
I am struggling With issue since three days.
I am using progress bar in Splash window. That Progress bar Run Correctly if i set await Task.Delay(1000) after one second my dll are going to load because Program wait for completing Delay time. After 1 sec my Progress bar stopped and my dll getting load.That make program lazy and its take much time to load application
i want both work simultaneously . My Progress bar Should run continuous and
My dll should run in back ground. After that it will open Login Window so please help me
Below is My Code
I created Progress bar in Xaml.

<ProgressBar Minimum="0" Maximum="100" Height="10" Background="Transparent" Width="100" Foreground="Black" Name="pbStatus" IsIndeterminate="True" Grid.Column="1" Margin="4,29,-4,20" />


My Splash Window Code In App.Xaml.cs

var splashScreen = new SplashWindow();
            //this.MainWindow = splashScreen;
            //this.MainWindow.Close();
            splashScreen.Show();
           // System.Threading.Thread th = new System.Threading.Thread();
            //in order to ensure the UI stays responsive, we need to
            //do the work on a different thread
            Task.Factory.StartNew(() =>
            {
                //simulate some work being done
                System.Threading.Thread.Sleep(5000);

                //since we're not on the UI thread
                //once we're done we need to use the Dispatcher
                //to create and show the main window
                this.Dispatcher.Invoke(() =>
                {
                    //initialize the main window, set it as the application main window
                    //and close the splash screen
                    var mainWindow = new Views.Common.LogIn();
                    this.MainWindow = mainWindow;
                        mainWindow.Show();
                    splashScreen.Close();
                });
            });







我怎样才能解决这个问题



我尝试过:






How can i over come with this issue

What I have tried:

this.Dispatcher.Invoke(() =>
                {
                    //initialize the main window, set it as the application main window
                    //and close the splash screen
                    var mainWindow = new Views.Common.LogIn();
                    this.MainWindow = mainWindow;
                        mainWindow.Show();
                    splashScreen.Close();
                });
            });







<pre>Task.Run(() =>
        {
             var mainWindow = new Views.Common.LogIn();
                    this.MainWindow = mainWindow;
                        mainWindow.Show();
                    splashScreen.Close();
        }

推荐答案

这篇MSDN杂志文章将向您展示如何做你想做的事:异步编程 - 从头开始​​的异步 [ ^ ]



更新:在下面的评论中,您指出UI仍然显示为锁定。这通常是因为您试图在UI上运行太多hread on start。



多线程如果你不熟悉它,SynchronizationContext和UI消息泵的工作原理并不简单。本文将详细介绍这一点。使用可下载的示例代码并对其进行修改,直到您理解它为止,然后修改应用程序中的代码。
This MSDN Magazine article will show you how to do what you want: Asynchronous Programming - Async from the Start[^]

UPDATE: In your comments below you indicate that the UI still appears to lock up. This is usually because you are trying to run too much on the UI thread on start up.

Multithreading is not simple if you are not familiar with how it, the SynchronizationContext, and the UI message pump works. This is explained in a lot of detail in the article. Work with the downloadable sample code and modify it until you understand it, then modify the code in your app.


这篇关于如何连续运行进度条,直到DLL未正确加载。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆