This will either automatically create a copy of the constant before it's passed to the method, as a constant can not be changed, or it will produce a compilation error, as you have to copy the value yourself.
What it looks like you are trying to do from the code, is to make a constant argument, which is not supported in C#.
How to use const member function in C#.
Methods are always constant, you can never change the definition of a method at runtime.
Talking about the designers of C# making something complicated or what!
I have built a LogViewer application and my objective is to terminate the application if it determines there are no log files to display or if the logfile is in use by another application.
I run the application from Main as follows:
In MainForm, it first does InitializeComponent, then it Populates the LogSelector with some user choices and then it adds logging info to the appropriate control if a log file is available (DisplayLogInfo).
If DisplayLogInfo detects that no logfile is available or the logfile is being used by another app, I want LogViewer to not show any form and to terminate.
I have tried this.Hide(). I have tried Application.Exit(). I have tried to make the form invisible by setting this.Visible to false. I have tried this.Dispose(), but then I get an unhandled exception and would rather not handle the exception by ignoring it.
Regardless, the form always displays and I have to close the app via closing the Window by the Close button.
Can anyone suggest a way to get this to work.
I would rather not rewrite the app. so that it checks for the logfile before running InitializeComponent as I believe there must be a way to accomplish the task as I have written it and I would like to learn how it can be done.
First, I gave you bad (or at least incomplete) advice. I meant to say to use the Application.Idle event rather than the Load event. Calling Close from the Load event can cause a memory leak. You could do something like:
publicpartialclass MainForm : Form
InitializeComponent(); <br> <br>
// Code to determine whether to close form <br>if (ShouldClose)
Application.Idle += new EventHandler(Application_Idle);
} <br> <br>
void Application_Idle(object sender, EventArgs e)
The Hide and Close methods don't work in the constructor because the Form is still being constructed. And in any case you don't want to close the form at this point, assuming the calling code looks something like:
If MainForm is closed and disposed before it is constructed, then Application.Run will throw an ObjectDisposedException.
I have this Windows app.
When the user clicks on a button (any button), after the event handler is done, the form is supposed to have focus returned (like if there's a MessageBox involved).
However, I've noticed that the user is forced to click once on the form to regain focus.
To illustrate (and this sounds weirder)...
The user hits a button, a MessageBox appears saying "are you sure?", and the user hits "no".
The messagebox disappears. But the button still has focus (understandable). If the user clicks on a different button, that same button still has focus and Windows thinks the user just clicked it instead of the other button that they clicked. The user has to click once on the form (even though the form visually seems to have focus, with the title bar dark blue and everything) before clicking on any other button.
I have a method which is run as a thread and at the end of it I have:
XtraForm2 form2 = new XtraForm2();
and the thing is that the windows just flashes - opens and imidiately closes
how can I solve it??
Thread wat = new Thread(GetData);
// This next line is required since you're going to be // creating UI controls on the thread.
// This next line will prevent the application from exiting if the background thread is still running.
wat.IsBackground = false;
Let me ask you a question, though: why are you creating a new thread to create the form? You're creating lots of extra work for yourself by creating a new thread to launch the form. If you keep all the UI controls created on the same thread, things will be much easier for you.
Thus, I recommend you create all your UI controls on the same thread.
the application looks like this:
I start it, and there is a button which is pressed and then the method GetData is started as a thread and after it processes all the data a second window pops up with a report, so I don't make a new thread for the second window
Last Visit: 31-Dec-99 18:00 Last Update: 24-Sep-23 20:57