Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileSystemWatcher with winforms Form as SynchronizingObject: event handlers not called on forms thread #52644

Closed
msneijders opened this issue May 12, 2021 · 3 comments · Fixed by #53151
Assignees
Milestone

Comments

@msneijders
Copy link

Description

Using FileSystemWatcher on a Winforms Form, setting SynchronizeObject to this form and adding a Changed event handler. This handler is executed on a different thread (worker thread) than this Form was created on (main thread). According to docs it should execute on the main thread?

Small test solution:

WinFormsApp_FileSystemWatcher.zip

Configuration

.NET 5.0.6

Regression?

It is at least a regression coming from .NET Framework 4.7.1, but I haven't tested a previous .NET Core version.

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.IO untriaged New issue has not been triaged by the area owner labels May 12, 2021
@ghost
Copy link

ghost commented May 12, 2021

Tagging subscribers to this area: @carlossanlop
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Using FileSystemWatcher on a Winforms Form, setting SynchronizeObject to this form and adding a Changed event handler. This handler is executed on a different thread (worker thread) than this Form was created on (main thread). According to docs it should execute on the main thread?

Small test solution:

WinFormsApp_FileSystemWatcher.zip

Configuration

.NET 5.0.6

Regression?

It is at least a regression coming from .NET Framework 4.7.1, but I haven't tested a previous .NET Core version.

Author: msneijders
Assignees: -
Labels:

area-System.IO, untriaged

Milestone: -

@Balkoth
Copy link

Balkoth commented May 18, 2021

I can confirm this, as i just came across this issue and wanted to write a bug report myself. Even if SynchronizingObject is set to a Control on the UI-Thread and InvokeRequired is true, the event handlers are called from a different thread.

@thomsj
Copy link
Contributor

thomsj commented May 23, 2021

I also noticed this, a couple of months ago. I've just committed my fix.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label May 23, 2021
@jozkee jozkee removed the untriaged New issue has not been triaged by the area owner label Jun 16, 2021
@jozkee jozkee added this to the 6.0.0 milestone Jun 16, 2021
stephentoub pushed a commit to thomsj/runtime that referenced this issue Aug 13, 2021
Call `protected` `On...` event raising methods from `Notify...` methods,
to invoke `SynchronizingObject` when required.

Fix dotnet#52644
carlossanlop pushed a commit that referenced this issue Aug 13, 2021
Call `protected` `On...` event raising methods from `Notify...` methods,
to invoke `SynchronizingObject` when required.

Fix #52644
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Aug 13, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants