Questions tagged [ui-thread]

In some frameworks there's a dedicated thread that exclusively manages all UI objects. It's the developer's responsibility to use this thread for UI updates (e.g. adding, updating and removing controls).

In some frameworks (.Net, Android, iOS, Java Swing etc.) there's a dedicated thread that exclusivly creates and manages all the UI objects. Only this thread is allowed to modify UI objects (add, remove, set text on the button, etc). Other threads usually just post a request to make such modifications.

UI thread must never be paused for long with slow task (like communication over network or something computation intensive) as this would make all GUI non-responsive.

References

599 questions
17
votes
3 answers

How do I test Prism event aggregator subscriptions, on the UIThread?

I have a class, that subscribes to an event via PRISMs event aggregator. As it is somewhat hard to mock the event aggregator as noted here, I just instantiate a real one and pass it to the system under test. In my test I then publish the event via…
Thorsten Lorenz
  • 11,781
  • 8
  • 52
  • 62
17
votes
3 answers

Easy way to call method in new thread

I'm writing small app and now I discovered a problem. I need to call one(later maybe two) method (this method loads something and returns the result) without lagging in window of app. I found classes like Executor or Callable, but I don't understand…
Sk1X1
  • 1,305
  • 5
  • 22
  • 50
16
votes
6 answers

How to detect if we're on a UI thread?

For the sake of argument, consider a UI thread as a thread that has had a call to Application.Run() or one of it's overloads called on it and has an active message loop running. Is there a way of detecting if we're currently executing on such a…
Matthew Scharley
  • 127,823
  • 52
  • 194
  • 222
13
votes
5 answers

Run code on UI thread without control object present

I currently trying to write a component where some parts of it should run on the UI thread (explanation would be to long). So the easiest way would be to pass a control to it, and use InvokeRequired/Invoke on it. But I don't think that it is a good…
Martin Moser
  • 570
  • 6
  • 12
13
votes
2 answers

Why is a single threaded model used to update the UI as main thread?

The Qt doc says, As mentioned, each program has one thread when it is started. This thread is called the "main thread" (also known as the "GUI thread" in Qt applications). The Qt GUI must run in this thread. The Android doc says, Like…
Carina
  • 2,260
  • 2
  • 20
  • 45
12
votes
1 answer

iOS AVPlayer replaceCurrentItemWithPlayerItem:nil block UI Thread

It seems that the api replaceCurrentItemWithPlayerItem: will stuck the main thread for some seconds, I understand that replacing the item need the information of the new item which might take some time to preload. But questions come up that why…
zoww
  • 191
  • 1
  • 1
  • 11
11
votes
3 answers

Does onPreExecute() and onPostExecute() execute on the UI thread or on the thread from which the AsyncTask has been started?

I have been writing AsyncTask's for short background operations in android for quite some time and had a very basic question. If I start an AsyncTask from a separate thread and not the main UI thread, would my onPreExecute()andonPostExecute methods…
Swapnil
  • 1,870
  • 2
  • 23
  • 48
11
votes
2 answers

Android Service and UI Thread

I have a Service running in my app.. This Service has an object for sending message to the server and a function to get that object and use it. The object is initialized from the Service and yet when the UI gets this objects and use it - it looks…
Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154
10
votes
3 answers

Android - SQLite ContentResolver insert/delete/update on UI Thread?

I have looked through many examples/tutorials of using SQLite in Android. Let's say you have an app that uses SQLite, ContentProvider, CursorLoader, a custom CursorAdapter. Now all major examples of this that I've found rely on a CursorLoader to…
Leo K
  • 808
  • 1
  • 9
  • 24
10
votes
4 answers

Android UI: when can I directly modify a view?

I have an app with two activities. From the main activity I start a secondary activity using startActivityForResult(). The secondary activity returns data (in the form of an Intent object) to the main activity. On the main activity I have a method…
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
9
votes
1 answer

android addView in background thread

I need to add lots of views in a loop, while this fragment does that, the app will also have a navigation drawer and action bar where the user can do things. so I would like this process to not a) slow down the app by blocking the user, b)…
CQM
  • 42,592
  • 75
  • 224
  • 366
9
votes
2 answers

What happens to an AsyncTask when the launching activity is stopped/destroyed while it is still running?

I've seen few questions nearly identical to mine, but I couldn't find a complete answer that satisfies all my doubts.. so here I am.. Suppose that you have an activity with an inner class that extends the AsyncTask class like this: public class…
Gianni Costanzi
  • 6,054
  • 11
  • 48
  • 74
8
votes
6 answers

How to execute some code in Android UI thread async?

I'm new to Android development. I've be working on Swing and SWT for several years. Both Swing and SWT has a stratage to execute code in UI thread sync and async. The typical usage is doing some time-consume staff in one thread then display the…
DeepNightTwo
  • 4,809
  • 8
  • 46
  • 60
8
votes
1 answer

What is the relationship between the JavaScript thread and the Silverlight UI thread?

JavaScript is single threaded - Silverlight is not, but interaction between JavaScript and Silverlight must be performed on the Silverlight UI thread. However, what exactly is the relationship between the Silverlight UI thread and the JavaScript…
SoftMemes
  • 5,602
  • 4
  • 32
  • 61
8
votes
4 answers

How to determine whether a class is instantiated within a console application or wpf?

I need to write a wrapper around a third party api that peruses message pumps and hence needs to be handled very differently depending on whether the wrapper is instantiated on a UI thread (such as within a wpf application) or not (such as a…
Matt
  • 7,004
  • 11
  • 71
  • 117
1
2
3
39 40