2012-10-02 4 views
0

일부 작업을 처리 할 수있는 배경 작업자가 있습니다. do_work 이벤트에 루프가 있으며 카운터 내에서 reportprogress를 호출하는 동안 카운터가 증가하지만 진행 표시 줄은 이동하지 않습니다. 1에서 100까지 reportprogress를 호출하는 간단한 for 루프를 사용하면 진행률 표시 줄이 작동합니다. - 하나의 연결된 다른 배경 작업자진행 표시 줄이 작동하지 않습니다.

InterfaceConvertLonLat con = new InterfaceConvertLonLat(); 
... 
con.backgroundWorker1.ReportProgress(counter); 

그래서 당신이보고있는 진행 : 코드의 액수가 미안 ..

namespace ConvertOSGB_WGS84 
{ 
public partial class InterfaceConvertLonLat : Form 
{ 
    public static Int32 OGB_M = 150; 
    [DllImport("TTDatum3.Dll", EntryPoint = "WGS84ToLocal", CallingConvention = CallingConvention.StdCall, SetLastError = true)] 
    public static extern Int32 WGS84ToLocal([In, Out]ref double lat, [In, Out] ref double lon, Int32 datum); 

    [DllImport("TTDatum3.Dll", EntryPoint = "LocalToWGS84", CallingConvention = CallingConvention.StdCall, SetLastError = true)] 
    public static extern Int32 LocalToWGS84([In, Out]ref double lat, [In, Out] ref double lon, Int32 datum); 

    [DllImport("TTDatum3.Dll", EntryPoint = "OSGB36ToOSGBGrid", CallingConvention = CallingConvention.StdCall, SetLastError = true)] 
    public static extern Int32 OSGB36ToOSGBGrid(double lat, double lon, [In, Out] ref double east, [In, Out] ref double north); 

    [DllImport("TTDatum3.Dll", EntryPoint = "OSGBGridToOSGB36", CallingConvention = CallingConvention.StdCall, SetLastError = true)] 
    public static extern Int32 OSGBGridToOSGB36(double east, double north, [In, Out] ref double lat, [In, Out] ref double lon); 
    CovertLonLat convert = new CovertLonLat(); 


    public InterfaceConvertLonLat() 
    { 
     InitializeComponent(); 
     Shown += new EventHandler(Form1_Shown); 
     backgroundWorker1.WorkerReportsProgress = true; 
     backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged); 
     backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork); 

    } 
    public void ConvertLonLat_Load(object sender, EventArgs e) 
    { 

    } 

    public void Form1_Shown(object sender, EventArgs e) 
    {  
     backgroundWorker1.RunWorkerAsync(); 
    } 

    public void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) 
    { 
     MessageBox.Show("backgroundworker"); 
     SqlConnection conn = new SqlConnection(Connections.dbConnection1()); 
     InterfaceConvertLonLat con = new InterfaceConvertLonLat(); 
     SqlCommand cmd = new SqlCommand(); 
     SqlCommand cmd1 = new SqlCommand(); 
     SqlDataAdapter adapter = new SqlDataAdapter(); 
     DataSet address = new DataSet(); 
     int counter = 0; 


     cmd.Parameters.Clear(); 

     if (conn.State.Equals(System.Data.ConnectionState.Closed)) 
     { 
      conn.Open(); 
     } 
     try 
     { 
      adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; 
      cmd1.Parameters.Add(new SqlParameter("@LTW", SqlDbType.Float)); 
      cmd1.Parameters.Add(new SqlParameter("@LGW", SqlDbType.Float)); 


      string dbQuery = "select * from paf "; 

      cmd.CommandText = (dbQuery); 
      cmd.CommandType = CommandType.Text; 
      cmd.Connection = conn; 
      adapter.SelectCommand = cmd; 
      adapter.Fill(address, "OBG36ToWGS84"); 

      foreach (DataRow LonLat in address.Tables[0].Rows) 
      { 
       counter++; 
       MessageBox.Show("value " + counter); 
       con.backgroundWorker1.ReportProgress(counter); 
       Double lon = 0; 
       Double lat = 0; 

       lat = Convert.ToDouble(LonLat["LTO"]); 
       lon = Convert.ToDouble(LonLat["LGO"]); 
       LocalToWGS84(ref lat, ref lon, OGB_M); 

       cmd1.Parameters["@LTW"].Value = lat; 
       cmd1.Parameters["@LGW"].Value = lon; 

       string dbQuery1 = "update paf set LTW = @LTW, LGW = @LGW"; 

       cmd1.CommandText = (dbQuery1); 
       cmd1.CommandType = CommandType.Text; 
       cmd1.Connection = conn; 
       cmd1.ExecuteNonQuery(); 

      } 
     } 
     catch (Exception ex) 
     { 

      MessageBox.Show("error converting: " + ex.Message); 
     } 
     finally 
     { 

      conn.Close(); 

     } 
    } 

    public void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) 
    { 

     progressBar1.Value = e.ProgressPercentage; 
    } 




} 

}

답변

2

이 문제입니다 표시되지 않은 양식으로 그냥 다음 코드를 사용하십시오 :

backgroundWorker1.ReportProgress(counter); 
+0

다른 클래스의 코드가 바뀌었기 때문에 거기에있었습니다. 감사합니다! –

+0

당신은 좋은 사람입니다 존, 그게 전부입니다! –

관련 문제