由於某種原因,我的Windows窗體在運行程序後立即關閉。我可以看到表格大約一秒鐘,然後關閉。這裏是我的形式加載方法加載後立即關閉windows窗體
private void Form1_Load(object sender, EventArgs e)
{
CustGen = new CustomerGenerator();
fuelType = null;
//set data on form initialization.
unleadedtank = 10000f;
dieseltank = 10000f;
u_price = 136.9f;
d_price = 152.2f;
//event subscriptions
CustGen.CustomerReady += CustomerReadySub; //Subscribes to ready event
CustGen.PumpProgress += PumpProgressSub; //subscribes to progress event
CustGen.PumpingFinished += PumpingFinishedSub; //subscribes to stop event
}
,這裏是我的針對特定形式的Program.cs,雖然這是自動生成的,我不知道是否需要它。
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
這是customerGenerator類
public class CustomerGenerator
{
public CustomerGenerator();
public event CustomerGenerator.CustomerReadyHandler CustomerReady;
public event CustomerGenerator.PumpingFinishedHandler PumpingFinished;
public event CustomerGenerator.PumpProgressHandler PumpProgress;
public void ActivatePump();
public void Start();
public delegate void CustomerReadyHandler(object sender, CustomerReadyEventArgs e);
public delegate void PumpingFinishedHandler(object sender, EventArgs e);
public delegate void PumpProgressHandler(object sender, PumpProgressEventArgs e);
}
我已經運行該程序,並開展哪些用戶之一,在下面的意見後說碰到這個來到之內。
public void CustomerReadySub(object sender, CustomerReadyEventArgs fuel)
{
string CustReady = null;
//checks what fuel is chosen and then activates the pump
fuelType = fuel.SelectedFuel.ToString();
if (!String.IsNullOrEmpty(fuelType))
{
fTypeLabel.Text = fuelType;
這是拋出異常的線。另外它說:「跨線程操作無效:控制'Form1'從一個線程訪問,而不是它創建的線程。」
fuelType = fuel.SelectedFuel.ToString();
感謝
如何顯示初學者的所有相關代碼..? – MethodMan 2013-04-21 22:03:24
如果你刪除Form1_Load的正文,它的工作原理? – 2013-04-21 22:03:25
你有沒有通過代碼..?如何定義'CustGen = new CustomerGenerator();' – MethodMan 2013-04-21 22:04:14