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
8
votes
2 answers

c# progressbar not updating

I have a ProgressBarWindow which has a progressbar and a cancel button on it which I use to report progress on file I/O. However, the UI Thread of the ProgressBarWindow and my main window both hang despite all the work being done in a…
CalumMcCall
  • 1,665
  • 4
  • 24
  • 46
8
votes
1 answer

No error "Only the original thread that created a view hierarchy can touch its views" when the view is updated without delay

I was faced with an interesting problem. If you write the following code in the onCreate/onStart/onResume method of activity: final Button myButton = (Button)findViewById(R.id.myButton); final TextView myTextView =…
7
votes
3 answers

Force redraw before long running operations

When you have a button, and do something like: Private Function Button_OnClick Button.Enabled = False [LONG OPERATION] End Function Then the button will not be grayed, because the long operation prevents the UI thread from repainting…
Maestro
  • 9,046
  • 15
  • 83
  • 116
7
votes
1 answer

Xamarin Forms: Should ObservableCollection always be set/updated in the UI thread?

Recently, I had to implement infinite scrolling / lazy loading on my PCL ListView. I will leave out most of the code, but the most important part was: ViewModel var countries = // get countries foreach (var country in countries) { …
Mark13426
  • 2,569
  • 6
  • 41
  • 75
7
votes
2 answers

Best strategy to update QTableView with data in real-time from different threads

I have application that for now starting few threads ( like 5 – 10 ) to collect data from different source . They are separated from the main GUI thread so I don’t feel any slowness in the GUI and I can keep working while the background threads are…
user63898
  • 29,839
  • 85
  • 272
  • 514
6
votes
2 answers

How can I find out whether method executes on UI thread or not in a decoupled way?

Here is the problem I have: I need to make sure an object is instantiated on the UI thread. If it is not, it should throw an exception. But how do I check inside a method whether it is running on the UI thread? Note: I do not want to pass any…
user65199
6
votes
1 answer

Is SQL or general file access appropriate in the Android main UI thread?

I'm trying to follow Android best practices, so in debug mode I turn all the following on: StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); //detect and log all thread…
Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
6
votes
2 answers

Why can only the UI thread in Android update the UI?

Could someone please explain to me why only the UI thread in Android can update the UI? Why can't any other thread update the UI?
Dhiral Pandya
  • 10,311
  • 4
  • 47
  • 47
6
votes
2 answers

Need to prioritize asynchronous socket reads in C#

My application pre-fetches a large number of video frames using asynchronous HttpWebRequest requests. So, if there are 100 frames, the prefetcher will request all 100 frames asynchronously, all at once, and process when received back. i.e. it makes…
Jacko
  • 12,665
  • 18
  • 75
  • 126
6
votes
3 answers

Android, creating a simple thread that will updated my seconds counter

Basically, I am trying to run a seconds counter and a levels counter. For every 10 seconds I want to ++level. But that's not implemented as yet, so far I am just trying to get the seconds to display but I am getting runtime exceptions and a…
Ryan
  • 9,821
  • 22
  • 66
  • 101
6
votes
0 answers

Android UI render time

I got in Android Vital a warning that my UI render time is slow. As they explained in vital page: Frozen UI frames: Percentage of daily sessions during which users experienced more than 0.1% of frames with a render time greater than 700ms. A…
6
votes
1 answer

Android: Possible for background thread to block until UI thread finishes operation?

Is it possible for a background thread to enqueue a message to the main UI thread's handler and block until that message has been serviced? The context for this is that I would like my remote service to service each published operation off its main…
zer0stimulus
  • 22,306
  • 30
  • 110
  • 141
6
votes
1 answer

Background Task sometimes able to update UI?

I just answered a question about whether a Task can update the UI. As I played with my code, I realized I'm not clear myself on a few things. If I have a windows form with one control txtHello on it, I'm able to update the UI from a Task, it seems,…
Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
6
votes
3 answers

handler, I want to run periodically

Using handler wants to run periodically The count is 0, if the countis 1, else Please fix this code. mRunnable = new Runnable(){ @Override public void run() { if (count == 0) { setImage(); count = 1; } else { weather =…
Jonghwan Seo
  • 71
  • 1
  • 1
  • 6
6
votes
2 answers

Android Unit Testing with AsyncTask and UI Updates Solution

Scenario: I'm trying to unit test the onClick handler of my application. Onclick does a simple search against a REST API, returns the results and updates the UI. Details: Onclick executes an AsyncTask, the doInBackground queries the REST API and…
bcdennis72
  • 161
  • 1
  • 6
1 2
3
39 40