Hello Forum,
I have a command that initializes some stuff, which can take a few seconds, and then shows a dialog form.
Because the initialization can take a few seconds, the user can click the AutoCAD button (wich triggers the command) multiple times if he is fast enough. This results in being the command run multiple times in a row.
How can I prevent this?
I've tried checking "GetSystemVariable("CMDNAMES")" to see if the command is already running, but this does not work because the commands do not run simultaneously, but after each other.
Thank you.
Hello,
I've tried it, but the command flag 'NoMultiple' does not solve this problem:
"The CommandFlags.NoMultiple indicates that the command will not be possible to repeat itself through the MULTIPLE command."
Thank you for the response.
Hello,
Doing some sort of check if the same command is already active, doesn't work in my case, because the commands run after each other, not simultaneously.
I have cancel in my button (^C^C) but that doesn't help, I think because the command shows a dialog form.
Thank you for the response.
Can't you just use a static counter?
public static int numOfTimes = 0; [CommandMethod("NumTest")] public void NumTest() { numOfTimes++; if (numOfTimes == 1) { Ed.WriteLine("First time ran"); } Ed.WriteLine("{0} time ran", numOfTimes); }
Or structure the function such that it first checks to see if the initialization is already done (presumably, data is added where it was missing before?) and only proceeds if initialization is required.
Hi,
I dont think I can use a counter, because I can't tell the difference between 2 situations:
- The user clicked the button fast 2 times in a row (the second time the command should not run).
- The user activated the command 2 times in a row on purpose (the second time the command should run).
Thank you for your response.
Hi,
The initialization needs to be done every time, because it shows files, and those files may have been altered between each session.
I will try to change the structure of the function in such a matter, that initialization is done in a later stage of the command, and the command is already running and the user can't click fast enough to activate it again (but this is more of a 'trick' then a solution to my problem).
Thank you for your response.
Would it help to change the cursor to a wait cursor and then back again with:
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor ''''' Your oode here System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
At the very least, it will notify the user that something is happening. Alternatively, open your dialog immediately with minimal data and update it once you've finished initializing it.