Flutter plugin async and threadWhat is the difference between a process and a thread?“implements Runnable” vs “extends Thread” in JavaAsynchronous vs Multithreading - Is there a difference?How do I update the GUI from another thread?What is a daemon thread in Java?How to use threading in Python?How and when to use ‘async’ and ‘await’async await blocking ui wp8What is the difference between asynchronous programming and multithreading?C# Async Await never returns to main thread

Overlapping circles covering polygon

Given this phrasing in the lease, when should I pay my rent?

Personal or impersonal in a technical resume

How were servants to the Kaiser of Imperial Germany treated and where may I find more information on them

"Oh no!" in Latin

Isometric embedding of a genus g surface

When and why was runway 07/25 at Kai Tak removed?

Deciphering cause of death?

Check if object is null and return null

ContourPlot — How do I color by contour curvature?

In One Punch Man, is King actually weak?

How do I tell my boss that I'm quitting in 15 days (a colleague left this week)

How to reduce predictors the right way for a logistic regression model

Has the laser at Magurele, Romania reached a tenth of the Sun's power?

Is there a RAID 0 Equivalent for RAM?

How to preserve electronics (computers, iPads and phones) for hundreds of years

What happens if I try to grapple an illusory duplicate from the Mirror Image spell?

How do I prevent inappropriate ads from appearing in my game?

Why the "ls" command is showing the permissions of files in a FAT32 partition?

Alignment of six matrices

Are Captain Marvel's powers affected by Thanos breaking the Tesseract and claiming the stone?

Is there anyway, I can have two passwords for my wi-fi

PTIJ: Which Dr. Seuss books should one obtain?

Mimic lecturing on blackboard, facing audience



Flutter plugin async and thread


What is the difference between a process and a thread?“implements Runnable” vs “extends Thread” in JavaAsynchronous vs Multithreading - Is there a difference?How do I update the GUI from another thread?What is a daemon thread in Java?How to use threading in Python?How and when to use ‘async’ and ‘await’async await blocking ui wp8What is the difference between asynchronous programming and multithreading?C# Async Await never returns to main thread













0















I have a flutter app that calls into a Java plugin using methodchannel.



I'm trying to understand the thread model and async behavior. So the order is like this...
A UI event handler calls await methodchannel.invoke("Foo", params). Which transfer control to the Java method call handler. There I reply.success to unblock the await in dart. The await returns and flutter UI event handler returns.



In the Java plugin I continue to the some more work after result.sucess. Say for another 2seconds.



The problem is (my question) during that 2 seconds, the dart main thread/UI is blocked, even though the flutter event handler had returned 2 seconds ago? Why is that? I can see from my logcat that dart and Java code are running in two separate threads. Your answer is appreciated.










share|improve this question
























  • Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

    – TruongSinh
    Mar 7 at 4:25












  • I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

    – herbert
    Mar 7 at 6:23












  • post your java code: most likely you are somehow blocking the UI main thread there

    – pskink
    Mar 7 at 6:50











  • I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

    – Günter Zöchbauer
    Mar 7 at 7:00






  • 1





    See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

    – Richard Heap
    Mar 7 at 14:13
















0















I have a flutter app that calls into a Java plugin using methodchannel.



I'm trying to understand the thread model and async behavior. So the order is like this...
A UI event handler calls await methodchannel.invoke("Foo", params). Which transfer control to the Java method call handler. There I reply.success to unblock the await in dart. The await returns and flutter UI event handler returns.



In the Java plugin I continue to the some more work after result.sucess. Say for another 2seconds.



The problem is (my question) during that 2 seconds, the dart main thread/UI is blocked, even though the flutter event handler had returned 2 seconds ago? Why is that? I can see from my logcat that dart and Java code are running in two separate threads. Your answer is appreciated.










share|improve this question
























  • Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

    – TruongSinh
    Mar 7 at 4:25












  • I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

    – herbert
    Mar 7 at 6:23












  • post your java code: most likely you are somehow blocking the UI main thread there

    – pskink
    Mar 7 at 6:50











  • I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

    – Günter Zöchbauer
    Mar 7 at 7:00






  • 1





    See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

    – Richard Heap
    Mar 7 at 14:13














0












0








0








I have a flutter app that calls into a Java plugin using methodchannel.



I'm trying to understand the thread model and async behavior. So the order is like this...
A UI event handler calls await methodchannel.invoke("Foo", params). Which transfer control to the Java method call handler. There I reply.success to unblock the await in dart. The await returns and flutter UI event handler returns.



In the Java plugin I continue to the some more work after result.sucess. Say for another 2seconds.



The problem is (my question) during that 2 seconds, the dart main thread/UI is blocked, even though the flutter event handler had returned 2 seconds ago? Why is that? I can see from my logcat that dart and Java code are running in two separate threads. Your answer is appreciated.










share|improve this question
















I have a flutter app that calls into a Java plugin using methodchannel.



I'm trying to understand the thread model and async behavior. So the order is like this...
A UI event handler calls await methodchannel.invoke("Foo", params). Which transfer control to the Java method call handler. There I reply.success to unblock the await in dart. The await returns and flutter UI event handler returns.



In the Java plugin I continue to the some more work after result.sucess. Say for another 2seconds.



The problem is (my question) during that 2 seconds, the dart main thread/UI is blocked, even though the flutter event handler had returned 2 seconds ago? Why is that? I can see from my logcat that dart and Java code are running in two separate threads. Your answer is appreciated.







multithreading asynchronous dart flutter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 7:01









Günter Zöchbauer

332k701005940




332k701005940










asked Mar 7 at 3:18









S. VagharS. Vaghar

66113




66113












  • Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

    – TruongSinh
    Mar 7 at 4:25












  • I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

    – herbert
    Mar 7 at 6:23












  • post your java code: most likely you are somehow blocking the UI main thread there

    – pskink
    Mar 7 at 6:50











  • I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

    – Günter Zöchbauer
    Mar 7 at 7:00






  • 1





    See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

    – Richard Heap
    Mar 7 at 14:13


















  • Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

    – TruongSinh
    Mar 7 at 4:25












  • I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

    – herbert
    Mar 7 at 6:23












  • post your java code: most likely you are somehow blocking the UI main thread there

    – pskink
    Mar 7 at 6:50











  • I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

    – Günter Zöchbauer
    Mar 7 at 7:00






  • 1





    See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

    – Richard Heap
    Mar 7 at 14:13

















Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

– TruongSinh
Mar 7 at 4:25






Hmm, I'm skeptical of the problem you're describing. What you have described is true, and all Dart code is async, and Dart and Java run all different thread, thus except if Dart is doing something CPU-heavy, it should not block main thread/UI.

– TruongSinh
Mar 7 at 4:25














I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

– herbert
Mar 7 at 6:23






I am pretty sure you are doing something weird, if this is really happening. Also, don't return a fake success. The callbacks are all asynchronous, and are meant to provide real results.. if you don't want your dart code to "block" just don't await .. you can handle the result using future's then callback, or await in another isolate.

– herbert
Mar 7 at 6:23














post your java code: most likely you are somehow blocking the UI main thread there

– pskink
Mar 7 at 6:50





post your java code: most likely you are somehow blocking the UI main thread there

– pskink
Mar 7 at 6:50













I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

– Günter Zöchbauer
Mar 7 at 7:00





I haven't done anything with plugins myself yet, but await itself does not block the UI, it only delays the execution of the code below await from being executed until the returned Future completes. Other async code can still be called (from timers, or animation triggers, or other code invoked by the framework for example depending on screen refresh rate. I don't know though if calling out to Java can block the UI thread.

– Günter Zöchbauer
Mar 7 at 7:00




1




1





See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

– Richard Heap
Mar 7 at 14:13






See this issue - the native code runs on the native UI thread, so you shouldn't block it or you risk stalling input and other platform specific issue. The solution is to do your additional 2 seconds of work on a separate thread. (The creator of the above issue argues that you should be able to do work on the main thread, but not many people seem to agree...) The point is there's an easy work around - background thread. I thought I saw a really good diagram of the 3 main threads the other day, but now I can't find it again.

– Richard Heap
Mar 7 at 14:13













0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55035528%2fflutter-plugin-async-and-thread%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55035528%2fflutter-plugin-async-and-thread%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко