Workflow 4.0 workflow to start an external process

I am trying to run Workflow 4.0 and hope to write user activity to run an external executable, wait for this process to complete, and then resume the next steps in the workflow.

I found the following example that shows (at the bottom of the page) how to write an operation while waiting for a file to arrive in a specific directory:

Creating Custom Actions with Workflow 4.0

I have a couple of problems with an example. First, when I add the following code:

void FileCreated(object sender, FileSystemEventArgs e)
{
    instance.ResumeBookmark(bookmarkName, e.FullPath);
    fsw.Dispose();
}

instance.Resumebookmark(...)seems to be unavailable, but instance.BeginResumeBookmarkalso instance.EndResumeBookmark.

I'm also not sure how to change this to deal with external processes, and not just browse the contents of a directory.

Is this even the best approach for this kind of thing?

+3
2

AyncCodeActivity . , :

    public sealed class RunProcess : AsyncCodeActivity<int>
    {
        public InArgument<string> FileName { get; set; }
        public InArgument<string> Arguments { get; set; }

        private Func<string, string, int> runProcessAsyncCall;

        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            this.runProcessAsyncCall = this.RunProcessImpl;
            return runProcessAsyncCall.BeginInvoke(FileName.Get(context), Arguments.Get(context), callback, state);
        }

        protected override int EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            return this.runProcessAsyncCall.EndInvoke(result);
        }

        private int RunProcessImpl(string fileName, string arguments)
        {
            Process p = Process.Start(fileName, arguments);
            p.WaitForExit();
            return p.ExitCode;
        }
    }

, , . , , , AsyncCodeActivity (, , ).

+3

. Process.WaitForExit, , , ExitCode .

+2

Source: https://habr.com/ru/post/1725189/


All Articles