Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6337885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:20:15+00:00 2026-05-24T19:20:15+00:00

I need to execute Show created file name each time Watch files fires an

  • 0

Workflow

I need to execute Show created file name each time Watch files fires an event

WatchFilesActivity : NativeActivity

    protected override void Execute(NativeActivityContext context)
    {
        var fileSystemWatcher = new FileSystemWatcher(context.GetValue(Path));
        fileSystemWatcher.IncludeSubdirectories = context.GetValue(IncludeSubdirectories);
        fileSystemWatcher.Filter = context.GetValue(Filter);

        var bookmark = context.CreateBookmark(ResumeFileCreatedBookmark);
        context.GetExtension<FileSystemWatcherExtension>().Start(fileSystemWatcher, bookmark);
    }

Extension

    public class FileSystemWatcherExtension : IWorkflowInstanceExtension
    {
        WorkflowInstanceProxy instance;
        Bookmark bookmark;

        public void SetInstance(WorkflowInstanceProxy instance)
        {
            this.instance = instance;
        }

        IEnumerable<object> IWorkflowInstanceExtension.GetAdditionalExtensions()
        {
            yield break;
        }

        public void Start(FileSystemWatcher fileSystemWatcher, Bookmark bookmark)
        {
            this.bookmark = bookmark;
            fileSystemWatcher.Created += new FileSystemEventHandler(FileCreated);
            fileSystemWatcher.EnableRaisingEvents = true;
        }

        void FileCreated(object sender, FileSystemEventArgs e)//When the file arrives
        {
            instance.BeginResumeBookmark(bookmark, e.FullPath, CompleteResume, null);
        }

        void CompleteResume(IAsyncResult ar)
        {
            var result = instance.EndResumeBookmark(ar);
        }
    }

This is working great, but only once, and after this the host closes.

I can’t put a WhileActivity because I need to handle consecutive very fast file creations and the processing time of an incoming file(Show created file name, in this case) is greater than the file creation rate

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:20:16+00:00Added an answer on May 24, 2026 at 7:20 pm

    For a starter I would make the Show created file name activity a child activity of the Watch files activity so it can control it’s execution. Next I would add a bookmark resumption callback so Watch files activity can react to and schedule the Show created file name activity in the callback.

    Optionally you might want to create your bookmark with BookmarkOptions.MultipleResume so you can handle as many file events as you want and only move on when you want to do so.

    public class WatchFilesActivity : NativeActivity
    {
        public Activity Child {get; set;}
    
        protected override void Execute(NativeActivityContext context)
        {
            var fileSystemWatcher = new FileSystemWatcher(context.GetValue(Path));
            fileSystemWatcher.IncludeSubdirectories = context.GetValue(IncludeSubdirectories);
            fileSystemWatcher.Filter = context.GetValue(Filter);
    
            var bookmark = context.CreateBookmark(ResumeFileCreatedBookmark, OnFileCreated, BookmarkOptions.MultipleResume);
            context.GetExtension<FileSystemWatcherExtension>().Start(fileSystemWatcher, bookmark);
        }
    
        protected void OnFileCreated(NativeActivityContext context, Bookmark bookmark, object value)
        {
            var fileName = (string)value
            context.ScheduleActivity(Child);
        }
    }
    

    Note: Code typed in Notepad so possible typos.

    If you need to pass the file name on to the child activity you can use an ActivityAction to do just that. See here for an example using an ActivityFunc which is just like an ActivityAction except it also has a return value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need execute some code before Windows shutdown process each time. So, I want
I am uploading files to ftp using FtpWebRequest . I need to show the
I need execute an SQL query in ORACLE it takes a certain amount of
I need to execute a large set of SQL statements (creating a bunch of
I need to execute a directory copy upon a user action, but the directories
I need to execute a select and then update some of the rows in
I need to execute MDX query from command line (MS AS 2005). I have
I need to execute a http web request from Plesk's Task Scheduler (using shared
I need to execute a PowerShell script from within C#. The script needs commandline
I need to execute a script in the background through a service. The service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.