Question System.ObjectDisposedException was unhandled

Socarsky

Well-known member
Joined
Mar 3, 2014
Messages
59
Programming Experience
Beginner
I face with that issue, I checked some links on the Internet but failure to find an viable.
My issue comes out when I close second form's FormClosed event I think a delegate causes this matter. First is a login form when login passes correctly then I make the first form hide and second forms come alone on the screen. That delegate for a stopwatch that I show elapsed time on the statusbar.


Note: this line causes problem : this.Inviko(db);
and : The update method called mainForm (second) one.

I call MainForm from loginPass form below:
C#:
this.Hide();
MainForm mainform = new MainForm();
mainform.strUser = txtUsername.Text;
mainform.ShowDialog();



namespace QCTX
{
    public partial class MainForm : DevComponents.DotNetBar.Office2007Form
    {

        // global variable
        string timeelepse = string.Empty;
        public string strUser;
        public MainForm() {
            InitializeComponent();

            // in button click handler
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            System.Threading.Thread t = new System.Threading.Thread(delegate()
            {
                while (true) {
                    TimeSpan ts = sw.Elapsed;

                    string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}",
                    ts.Hours, ts.Minutes, ts.Seconds);

                    timeelepse = elapsedTime;

                    UpdateLabel();
                }
            });
            t.Start();

        }

        public delegate void doupdate();
        public void UpdateLabel()
        {
            doupdate db = new doupdate(DoUpdateLabel);
            if (!this.IsDisposed) { this.Invoke(db); } 
        }

        public void DoUpdateLabel()
        {
            labelItem2.Text = timeelepse;
        }

        private void MainForm_Load(object sender, EventArgs e) {
            DateTime dtime = DateTime.Today;
            dateTimeInput1.Value = dtime;
            DateTime zaman = DateTime.Now;
            labelItem1.Text = "User name: (" + strUser + ")  --> Logon time: (" + zaman + ")  --> Duration: (" + labelItem2.Text + ")";
        }

    }
}

 
I didn't ask you whether you had posted somewhere. Look at the top of this page. This thread is in the ASP.NET Web Forms forum. I'm asking whether it should actually have been posted in the Windows Forms forum because it looks like a Windows Forms application and not Web Forms.
 
I didn't ask you whether you had posted somewhere. Look at the top of this page. This thread is in the ASP.NET Web Forms forum. I'm asking whether it should actually have been posted in the Windows Forms forum because it looks like a Windows Forms application and not Web Forms.
I'm sorry I didn't see this topic where I've done. I thought it's winforms in desktop application. Yes It must be the WinForm threads.
 
Back
Top Bottom