locked
FileSystemWatcher and task RRS feed

  • Question

  • Hi

    I have the following code to search files in 2 folders..

            public async Task ProcessFiles()
            {
                var processVivere = MonitoringVivere();
                var processOfficeBanking = MonitoringSantanderConsumer();
    
                await Task.WhenAll(processVivere, processOfficeBanking);
            }
    
            #region Privates
    
            public async Task MonitoringVivere()
            {
                var fileSystemWatcher = new FileSystemWatcher
                {
                    Path = Vivere.RutaIn
                };
    
                fileSystemWatcher.Created += FileSystemVivereToOfficeBanking_Created;
                fileSystemWatcher.EnableRaisingEvents = true;
    
                await Task.Delay(1);
            }
    
            public async Task MonitoringSantanderConsumer()
            {
                var fileSystemWatcher = new FileSystemWatcher
                {
                    Path = OfficeBanking.RutaOut
                };
    
                fileSystemWatcher.Created += FileSystemOfficeBankingToVivere_Created;
                fileSystemWatcher.EnableRaisingEvents = true;
    
                await Task.Delay(1);
            }

    If I convert FileSystemVivereToOfficeBanking_Created to a async /await method...  I received an error.

    private void FileSystemVivereToOfficeBanking_Created(object sender, FileSystemEventArgs e) { ProcessVivereToOfficeBanking(e);

    }

    The error is:

    Task GetReleasesQueryHandler.FileSystemOfficeBankingToVivere_Created(object, FileSystemEventArgs)' has the wrong return type Pionner.Releases.Application C:\Users\User\Desktop\Santander.Pionner.Converters\Pionner.Releases.Application\10.Application\Querys\GetReleasesQueryHandler.cs

    How can I change FileSystemVivereToOfficeBanking_Created  and FileSystemOfficeBankingToVivere_Created as async/awt methods?


    Wednesday, October 7, 2020 3:54 AM

All replies

  • Hi neonash,
    Async event handlers need to be declared async void.
    More details you can refer to this document.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 8, 2020 2:54 AM