我有一个程序,用文本填充文本框。现在我想将文本框中的所有文本保存到文件中。
所以我创建了这个:
private void button3_Click(object sender, EventArgs e)
{
timer1.Stop();
saveFileDialog1.ShowDialog();
System.IO.StreamWriter file = new System.IO.StreamWriter("SaveFileDialog1.path");
file.WriteLine(" Time and date:\r\n " + textBox2.Text + "\r\n \r\n Memory:\r\n " + textBox1.Text + "\r\n " + textBox10.Text + "\r\n " + textBox4.Text + "\r\n " + textBox5.Text + "\r\n \r\n CPU:\r\n " + textBox6.Text + "\r\n " + textBox11.Text + "\r\n " + textBox12.Text + "\r\n " + textBox13.Text + "\r\n \r\n Network:\r\n " + textBox7.Text + "\r\n " + textBox3.Text + "\r\n " + textBox8.Text + "\r\n " + textBox9.Text + "\r\n ");
timer1.Start();
}
但是当我单击按钮时,我的程序将退出!我不知道为什么。
有人知道为什么或看到代码中有错误的部分吗?
这是调试输出的样子:
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'd:\documents\visual studio 2012\Projects\SystemControl\SystemControl\bin\Debug\SystemControl.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread 'vshost.NotifyLoad' (0x1dc8) has exited with code 0 (0x0).
The thread '<No Name>' (0x162c) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x19cc) has exited with code 0 (0x0).
'SystemControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'd:\documents\visual studio 2012\Projects\SystemControl\SystemControl\bin\Debug\SystemControl.exe', Symbols loaded.
The program '[5560] SystemControl.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[5560] SystemControl.vshost.exe: Managed (v4.0.30319)' has exited with code -2147483645 (0x80000003).
编辑:感谢您的所有回答,但是对于所有代码,程序在 savefiledialog1.showdialog(); 时崩溃;行已运行。我不知道为什么。但其他代码不会崩溃,只是那行代码是错误的。对话框不出现,程序强制退出。
最终编辑(重要):感谢大家帮助我和编写代码。但问题是:没有足够的 RAM 来加载 savefiledialog。当我在没有 Visual Studio 的情况下运行 .exe 时,它工作正常;-) 感谢大家帮助我!