Building a Command in a Function

You may try this button from here:

It incorporates a simple process dialog you probably can use as an example.