我已經使用VS 2010,C#構建應用程序。Winforms線程應用程序掛起(後臺工作線程)
我在我的應用程序中使用BackgroundWorker
。
雖然我點擊按鈕代碼從數據庫中獲取記錄並顯示到Datagrid中。 但問題是,當我從代碼運行它的工作正常,但是當我運行程序.exe所以它掛起。
//Declared delegate
delegate void SetControlPropertyThreadSafeDelegate(Control control, string propertyName, object propertyValue);
//Declared method to run control Thread safe
public static void SetControlPropertyThreadSafe(Control control, string propertyName, object propertyValue)
{
if (control.InvokeRequired)
{
control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe), new object[] { control, propertyName, propertyValue });
}
else
{
control.GetType().InvokeMember(propertyName, BindingFlags.SetProperty, null, control, new object[] { propertyValue });
}
}
//calling method like below
SetControlPropertyThreadSafe(dataGridView1, "DataSource", dtGrid2);
我不明白我犯的錯誤在哪裏。 爲什麼該程序掛?
一個調試器附加到掛起的應用程序和「破」了。這應該顯示你在這裏「掛起」。 – 2014-09-11 09:22:51
可是當我在調試模式下運行它,它不是掛 – Hardik 2014-09-11 09:25:31
我說:「一個調試器附加**的掛起的應用程序**」,在調試運行它。 VS可以連接到大多數應用程序或線程以進行調試。 – 2014-09-11 09:26:16