Skip to content

Consider adding Windows plugin API to post tasks to main thread #79213

Closed

Description

@stuartmorgan-g

There are plugin APIs that can only be called from the main thread, but there's not a particularly good way for Windows plugins to move calls to that thread AFAIK. Options include:

  • Each plugin doing the hidden-window message loop implementation themselves.
  • Using the top-level window proc override registration to send themselves a custom message and hope nobody else uses it in a way that interferes.

This came up in the Texture PR and the solution there was to make most of it thread-safe; applying that more broadly is another option (e.g., to event streams). But a generic way to move things to the main thread would avoid needing to make lots of thread-safe APIs.

Proposed API:

class FlutterEngine : public PluginRegistry {

  // ...

  // Schedule a callback to be called on the platform thread.
  //
  // This may be called on any thread. The callback is executed only
  // once on the platform thread.
  void PostPlatformThreadTask(std::function<void()> callback);
}
// Schedule a callback to be invoked on the engine's platform thread.
//
// This may be called on any thread. The callback is executed only
// once on the platform thread.
FLUTTER_EXPORT void FlutterDesktopEnginePostPlatformThreadTask(
    FlutterDesktopEngineRef engine,
    VoidCallback callback,
    void* user_data);

/cc @cbracken

(We would only do one of #134346 and this.)

Activity

  1. added
    engineflutter/engine related. See also e: labels.
    platform-windowsBuilding on or for Windows specifically
    on Mar 28, 2021
  2. Sunbreak commented on Mar 28, 2021

    @Sunbreak
    Contributor
    • Each plugin doing the hidden-window message loop implementation themselves.

    hidden-window message loop implementation for further reference: flutter-team-archive/engine#24232

  3. changed the title [-]Consider adding Windows plugin API to post talks to main thread[/-] [+]Consider adding Windows plugin API to post tasks to main thread[/+] on Mar 28, 2021
  4. added
    c: new featureNothing broken; request for a new capability
    P3Issues that are less important to the Flutter project
    on Apr 1, 2021
  5. sebastianhaberey commented on Sep 9, 2023

    @sebastianhaberey

    Just dropping in to say this would be immensely helpful for an issue I am currently facing with my plugin. Until then, would you advise me to use the linked commit as a template for a hidden message loop within the plugin?

  6. stuartmorgan-g commented on Sep 9, 2023

    @stuartmorgan-g
    ContributorAuthor

    Just dropping in to say this would be immensely helpful for an issue I am currently facing with my plugin.

    As discussed in flutter-team-archive/engine#31134, the preferred solution to the problem you describe in that issue is for the Windows embedding API to be made thread safe.

  7. 7 remaining items

  8. added
    team-linuxOwned by the Linux platform team
    and removed
    team-linuxOwned by the Linux platform team
    on Jun 6, 2024
  9. flutter-triage-bot commented on Jun 7, 2024

    @flutter-triage-bot

    The triaged-desktop label is irrelevant if there is no team-desktop label or fyi-desktop label.

  10. Ae-Mc commented on Aug 14, 2025

    @Ae-Mc
  11. loic-sharma commented on Jun 24, 2026

    @loic-sharma
    Member

    Added by: #187365

  12. github-actions commented on Jul 14, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  13. locked as resolved and limited conversation to collaborators on Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: desktopRunning on desktopa: pluginsSupport for writing, building, and running plugin packagesc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterengineflutter/engine related. See also e: labels.platform-windowsBuilding on or for Windows specificallyteam-windowsOwned by the Windows platform teamtriaged-windowsTriaged by the Windows platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions