Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
双击.exe时C#中的Progressbar_C#_Java_Visual Studio 2010_Launcher_Java Launcher - Fatal编程技术网

双击.exe时C#中的Progressbar

双击.exe时C#中的Progressbar,c#,java,visual-studio-2010,launcher,java-launcher,C#,Java,Visual Studio 2010,Launcher,Java Launcher,我有一个捆绑在ISO映像中的Java应用程序,它有一个用c#编写的启动器。 当我通过CD启动应用程序时,会有很长的等待时间,这会让用户错误地认为应用程序没有启动。我试图在java应用程序中放入progressbar,并在程序开始时调用它,但失败了。所以我尝试在发射器中启动progressbar 下面是启动器代码 Program.cs using System.Security.Principal; using System.Diagnostics; namespace RunMyprogram

我有一个捆绑在ISO映像中的Java应用程序,它有一个用c#编写的启动器。 当我通过CD启动应用程序时,会有很长的等待时间,这会让用户错误地认为应用程序没有启动。我试图在java应用程序中放入progressbar,并在程序开始时调用它,但失败了。所以我尝试在发射器中启动progressbar

下面是启动器代码

Program.cs

using System.Security.Principal;
using System.Diagnostics;

namespace RunMyprogram
{
static class Program
    {
 static void Main(string[] args)
        {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.CreateNoWindow = true;
                startInfo.UseShellExecute = false;
                startInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory + @"/myBatFile.bat";
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.Verb = "runas";
                Process.Start(startInfo);
}
}
}

请让我知道如何在此代码中添加进度条。

启动一个新线程,在该线程上显示添加点的进度。由于应用程序无法知道当前执行的状态,我们无法显示进度条,说明完成了多少%

您可以做的是显示一个无休止的进度选项,并显示一条消息,如“启动应用程序,这可能需要10分钟……感谢您的耐心。”

其代码如下所示:

using System.Security.Principal;
using System.Diagnostics;
using System.Threading;   // for ThreadStart delegate and Thread class
using System;             // for Console class

namespace RunMyprogram
{
    static class Program
    {
        static void Main(string[] args)
        {
                ThreadStart ts = new ThreadStart(ShowProgress);
                Thread t = new Thread(ts);
                t.Start();

                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.CreateNoWindow = true;
                startInfo.UseShellExecute = false;
                startInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory + @"/myBatFile.bat";
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.Verb = "runas";
                Process.Start(startInfo);

                t.Join();
        }

        static void ShowProgress()
        {
            // This function will only show user that the program is running, like aspnet_regiis -i shows increasing dots.

           Console.WriteLine(""); //move the cursor to next line
           Console.WriteLine("Launching the application, this may take up to 10 minutes..... Thanks for your patience.");

           // 10 minutes have 600 seconds, I will display 'one' dot every 2 seconds, hence the counter till 300
           for(int i = 0; i < 300; i++)
           {
               Console.Write(". ");
               Thread.Sleep(2000);
           }
        }
    }
}
使用System.Security.Principal;
使用系统诊断;
使用System.Threading;//对于ThreadStart委托和Thread类
使用系统;//控制台类
名称空间RunMyprogram
{
静态类程序
{
静态void Main(字符串[]参数)
{
ThreadStart ts=新的ThreadStart(显示进度);
螺纹t=新螺纹(ts);
t、 Start();
ProcessStartInfo startInfo=新的ProcessStartInfo();
startInfo.CreateNoWindow=true;
startInfo.UseShellExecute=false;
startInfo.FileName=System.AppDomain.CurrentDomain.BaseDirectory+@“/myBatFile.bat”;
startInfo.WindowStyle=ProcessWindowStyle.Hidden;
startInfo.Verb=“runas”;
进程启动(startInfo);
t、 Join();
}
静态void ShowProgress()
{
//此函数仅向用户显示程序正在运行,如aspnet_regiis-i显示递增的点。
Console.WriteLine(“”;//将光标移动到下一行
WriteLine(“启动应用程序,这可能需要10分钟……感谢您的耐心。”);
//10分钟有600秒,我将每2秒显示一个点,因此计数器一直到300
对于(int i=0;i<300;i++)
{
控制台。写(“.”);
《睡眠》(2000年);
}
}
}
}

您也可以使用
while(true)
(无止境)循环,而不是
for(int i=0;i<300;i++)
,但为此,您必须能够知道第二个应用程序是否已启动,所以,你可以有一个条件,从无限循环。

感谢代码。我们可以考虑一个进度条而不显示百分比。你想要一个包含进度条的Windows表单吗?不…我的意思是像JavaButt中的一个不确定的进度条,它们是图形的…让我知道您对基于控制台的应用程序的期望是什么以及如何,以便我能够指导我的需求是在launcher中有一个不确定的进度条(如java中的进度条),直到它启动.exe java应用程序