Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.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
C# 在c中执行方法时如何在Display中显示进度条#_C# - Fatal编程技术网

C# 在c中执行方法时如何在Display中显示进度条#

C# 在c中执行方法时如何在Display中显示进度条#,c#,C#,在我的应用程序中,当用户单击特定按钮时,我想在显示器中显示进度条 我实现了以下代码 private bool ImportData() { bool result = false; //Thread oThread = new Thread(new ThreadStart(frmWaitShow)); try { Thread backgroundThread = new Thread(

在我的应用程序中,当用户单击特定按钮时,我想在显示器中显示进度条

我实现了以下代码

 private bool  ImportData()
    {
        bool result = false;
        //Thread oThread = new Thread(new ThreadStart(frmWaitShow));
        try
        {
            Thread backgroundThread = new Thread(
            new ThreadStart(() =>
            {
            //oThread.Start();

                for (int n = 0; n < 100; n++)
                {
                    Thread.Sleep(50);
                    progressBar1.BeginInvoke(new Action(() => progressBar1.Value = n));
                }

            }
              ));
            backgroundThread.Start();
            // Progress Bar Should Start From here
            intdevid = int.Parse(cmbDeviceName.SelectedValue.ToString());
            FetchDevicedata(intdevid);  // Fetch Remove Device Info from SQL database
            //FTPTCompletedBatchTransfer();
            FetchMaxReportId();
            GetFTPFile(strDeviceIP, strDeviceUsername, strDevicePwd, strDevicePath + "//RunningBatch//RunningBatch.db", "RunningBatch.db"); // Copy RunningBatch.db to Debug Folder from Remote 
            LoadRunningData(); // Get Running Data in dataset from running.db
            DecodeBatchData_R(); // save in batch master and row data table
            GetFTPFile(strDeviceIP, strDeviceUsername, strDevicePwd, strDevicePath + "//CompletedBatch//CompletedBatch.db", "CompletedBatch.db");
            LoadCompletedData();
            DecodeBatchData();
            result = true;
            // Progress Bar Should Stop  here
        }
        catch (Exception ex)
        {
            clsLogs.LogError("Error: " + ex.Message + this.Name + " || ImportData");
            result = false;  
        }
        //oThread.Abort();
        return result; 
    }
private bool ImportData()
{
布尔结果=假;
//Thread oThread=新线程(新线程开始(frmWaitShow));
尝试
{
线程背景线程=新线程(
新线程开始(()=>
{
//oThread.Start();
对于(int n=0;n<100;n++)
{
睡眠(50);
progressBar1.BeginInvoke(新操作(()=>progressBar1.Value=n));
}
}
));
backgroundThread.Start();
//进度条应该从这里开始
intdevid=int.Parse(cmbDeviceName.SelectedValue.ToString());
FetchDevicedata(intdevid);//从SQL数据库中获取删除设备信息
//FTPTCompletedBatchTransfer();
FetchMaxReportId();
GetFTPFile(strDeviceIP、strDeviceUsername、strDevicePwd、strDevicePath+“//RunningBatch//RunningBatch.db”、“RunningBatch.db”);//将RunningBatch.db从远程复制到调试文件夹
LoadRunningData();//从Running.db获取数据集中的运行数据
DecodeBatchData_R();//保存在批处理主数据表和行数据表中
GetFTPFile(strDeviceIP、strDeviceUsername、strDevicePwd、strDevicePath+“//CompletedBatch//CompletedBatch.db”、“CompletedBatch.db”);
LoadCompletedData();
解码批处理数据();
结果=真;
//进度条应该到此为止
}
捕获(例外情况除外)
{
clsLogs.LogError(“错误:+ex.Message+this.Name+”| | ImportData”);
结果=假;
}
//oThread.Abort();
返回结果;
}

但是它没有正确地显示。。启动此进度条需要花费很多时间,在我的这些功能结束之前启动并在2秒内关闭。您可以使用
BackgroundWorker
,它支持进度指示