Click here to Skip to main content
15,843,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

C#
namespace Mizan
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMain());




C#
private void frmMain_Load(object sender, EventArgs e)
        {
            Application.ExitThread();





i want to exit from application but occur this error:
Cannot access a disposed object. Object name: 'frmMain'.
Posted
Comments
Manish.Insan 23-Dec-11 7:06am    
Are you quitting this from any child page?
faezun 23-Dec-11 8:48am    
this is a main page

Instead of Application.ExitThread() just use Close()
That will close the frmMain instance and terminate the application.
 
Share this answer
 
Comments
faezun 23-Dec-11 8:31am    
thanks
but Gives the previous error

if project run ,then exit no error occur
note: my solution have two project, and this project is startup project
C#
private void frmMain_Load(object sender, EventArgs e)
        {
         Application.ExitThread();
         frmCsarresid f2 = new frmCsarresid();    f2.ShowDialog();


i comment a row: The problem was solved

XML
private void frmMain_Load(object sender, EventArgs e)
        {
         Application.ExitThread();
         //frmCsarresid f2 = new frmCsarresid();    f2.ShowDialog();</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900