.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Prevent command from running multiple times in a row, by fast clicking of user

9 REPLIES 9
Reply
Message 1 of 10
Ertqwa
824 Views, 9 Replies

Prevent command from running multiple times in a row, by fast clicking of user

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.

9 REPLIES 9
Message 2 of 10
SENL1362
in reply to: Ertqwa

The CommandFlags.NoMultiple may prevent this:

[CommandMethod("Startup",CommandFlags.NoMultiple)]
Message 3 of 10
Ertqwa
in reply to: SENL1362

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.

Message 4 of 10
SENL1362
in reply to: Ertqwa

ok, sorry about that, just a quick guess.
Other possibilities are a:
-check CMDACTIVE
-set a static (global) var when starting
Message 5 of 10
Ertqwa
in reply to: SENL1362

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.

Message 6 of 10
jeff
in reply to: Ertqwa

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);
        }

 

You can also find your answers @ TheSwamp
Message 7 of 10
dgorsman
in reply to: jeff

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.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 8 of 10
Ertqwa
in reply to: jeff

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.

Message 9 of 10
Ertqwa
in reply to: dgorsman

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.

Message 10 of 10
bowa
in reply to: Ertqwa

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost