Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My program catches event msg from my .dll.
It then shows the MessageBox. Then exit the program.
However, you can ignore the MessageBox button and continue to use the program.
So I want to disable the program until I press the OK button.
I would like to disable the program.

What I have tried:

C#
private void ExitProgram(object sender, EventArgs e)
        {
            string msg = sender as string;
            Log.Instance.InsertLogError(msg);

            DateTime nowTime = DateTime.Now;

            while (Log.Instance.GetLogQueueCount() != 0 || nowTime.AddSeconds(10) < DateTime.Now)
            {
                Thread.Sleep(100);
            }
            Log.Instance.Dispose();

            MyProgramtWindowsModeErr(msg);
            //if (Program.bWindowMode == true)
            //    MessageBox.Show(msg, "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Error);

            (Process.GetCurrentProcess()).Kill();
        }


        public bool MyProgramtWindowsModeErr(string msg)
        {
            if (Program.bWindowMode == true)
            {
                MessageBox.Show(msg, "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return true;
        }


In MyProgramtWindowsModeErr, I checked true and fasle for each other.

However, I could not open the message box or continue using the program.
Help me plz..
Posted
Updated 8-Mar-19 16:25pm
Comments
Richard MacCutchan 8-Mar-19 4:09am    
MessageBox.Show does disable the program until it is responded to. Your code must be doing something different.
Richard MacCutchan 9-Mar-19 4:42am    
Your code is presumably looping inside the while (Log.Instance.GetLogQueueCount() != 0 || nowTime.AddSeconds(10) < DateTime.Now) statement;

All you have to do is display a modal dialog box, and execution will pause until you dismiss the dialog. It just so happens that MessageBox *is* modal. Of course, I'm assuming that you're not running any async processes or otherwise running multiple threads.
 
Share this answer
 
v3
public bool MyProgramtWindowsModeErr(string msg)
        {
            if (Program.bWindowMode == true)
            {
                if (DialogResult.OK == MessageBox.Show(msg, "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Error))
                {
                    return false;
                }
            }
            return true;
        }
 
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