Hello everybody,
I am treating the request of abandon by the user, in a recursive treatment (in a WinForms project, .Net 5.0).
The user has depressed the escape key, and thanks to GetAsyncKeyState, a confirmation has been given, and flags positioned, first to abandon current folder, and then after a messagebox, to abandon the rest of the treatment.
This last point is the difficulty. By putting the treatment in a condition
it is easy to abandon the current directory.
But imagine we are at the fifth level : abandoning the current folder is easy, but four parents are in the calls stack. Break does not go so far. End would close the form, which is not the aim, the user must be able to restart.
So, the treatment stops, that is OK, but if the user clicks on the button to start again, strange error messages appear
With a goto, I went to the end of the procedure, but that did not release the caller.
My first idea looked like this :
but then it had no loop to break. Hence the goto ... I imagine I am missing something there.
There is the possibility to throw an exception, that must be catched by the level above.
I imagine the catch has to throw the exception again, except if it is at the first level, otherwise the exception is thrown to the user. So, this supposes to increment a level integer variable, each time you enter a new level.
Do you think I am on the good path ?
I am treating the request of abandon by the user, in a recursive treatment (in a WinForms project, .Net 5.0).
The user has depressed the escape key, and thanks to GetAsyncKeyState, a confirmation has been given, and flags positioned, first to abandon current folder, and then after a messagebox, to abandon the rest of the treatment.
This last point is the difficulty. By putting the treatment in a condition
Condition to execute a procedure:
if(!totalabandon)
{
dostuff;
}
But imagine we are at the fifth level : abandoning the current folder is easy, but four parents are in the calls stack. Break does not go so far. End would close the form, which is not the aim, the user must be able to restart.
So, the treatment stops, that is OK, but if the user clicks on the button to start again, strange error messages appear
Type of strange error message:
System.IO.IOException: Incorrect parameter (followed by the path of a file)
With a goto, I went to the end of the procedure, but that did not release the caller.
My first idea looked like this :
C#:
foreach (FileInfo fi in di.GetFiles())
{
if ((GetAsyncKeyState(Keys.Escape) & 0x8000) != 0)
{
break;
}
}
but then it had no loop to break. Hence the goto ... I imagine I am missing something there.
There is the possibility to throw an exception, that must be catched by the level above.
I imagine the catch has to throw the exception again, except if it is at the first level, otherwise the exception is thrown to the user. So, this supposes to increment a level integer variable, each time you enter a new level.
Do you think I am on the good path ?
Last edited: