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

Why the UI thread is getting blocked?

In the below code I am trying to run a thread when a button is clicked. In the button listener I create a new thread and run it...but at run time, when the button is pressed, the button itself freezes and the app does not respond and I receive ANR…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
3
votes
2 answers

InvalidOperationException: The calling thread must be STA, because many UI components require this

You can find a lot of similar questions on SO, but no one (as I'm see) covers situation, when your logic must return something. In this code example I have simple CustomMessageBox (it's a window), which must return something, entered by user.…
Arman Hayots
  • 2,459
  • 6
  • 29
  • 53
3
votes
1 answer

Exception in async method executing in UI-thread crashes application

When I await on a method that throws an exception, try/catch do not save application from crashing. There is a throwing method void CurrentStep.Process(CancellationToken cancellationToken) { throw new Exception(); } It is called from the UI…
3
votes
1 answer

Android Fatal signal 6 (SIGABRT) from asyncTask

I have a working android game which occasionally force closes on slow devices with the error Fatal signal 6 (SIGABRT), code -6 in tid 14620 (AsyncTask #1) Research indicated to me that this was due to delaying the execution of the UI thread, so,…
3
votes
2 answers

Custom message pumping with c# async calls

I'm creating my own UI handling logic that runs on a single thread. Basically, what I'm doing is void HandlerMain() { while (true) { Task[] events = PumpEvents(); Task.WaitAll(events); } } where one example task that…
D. Fisher
  • 223
  • 2
  • 12
3
votes
0 answers

WebSocket inside a WebWorker - UI Thread still blocking

i'm using WebSockets to send data from my node.js server to my clients. Since the data can be kind of large, the UI thread used to block, so no user interaction or video playing was possible during the data was received. That's when i stumbled over…
mneundorfer
  • 109
  • 1
  • 11
3
votes
3 answers

F# cross-thread UI exception in WinForms App

I have a problem with developing a simple application in F#, which just reads the length of the requested HTML page. Seems to be that such an error would be similar for VB.NET/C# language too, when you develop the UI application. But I'm rather new…
user2402179
3
votes
3 answers

Update DataContext from background thread

I fetch data for a wpf window in a backgroundthread like this [framework 4.0 with async/await]: async void refresh() { // returns object of type Instances DataContext = await Task.Factory.StartNew(() => serviceagent.GetInstances()); var…
Gerard
  • 13,023
  • 14
  • 72
  • 125
3
votes
4 answers

Interacting with the UI thread from an Async callback method?

I have a method that is asynchronously called when System.Net.Sockets.NetworkStream.BeginRead completes. skDelegate = New AsyncCallback(AddressOf skDataReceived) skStream.BeginRead(skBuffer, 0, 100000, skDelegate, New Object) In that callback…
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
3
votes
6 answers

WPF/C# Don't block the UI

I've an existing WPF application, which has several sections. Every section is a UserControl, that implements an interface. The interface specify two methods: void LoadData([...]) and bool UnloadData(). Those method are called by the UI thread, so…
J4N
  • 19,480
  • 39
  • 187
  • 340
3
votes
2 answers

Worker thread from AsyncTask blocks UI thread

I'm making an android application which downloads JSON file in the AsyncTask class after SEARCH BUTTON in Activity is clicked. And I want to display Progress Dialog on the Activity while downloading data. But on my AVD and device, actual action is…
KAKY
  • 61
  • 1
  • 6
3
votes
5 answers

Android: Updating text in the UI thread issue

I'm very new to Android. I've used Java before but not for around a year and a half. I'm having problems getting the screen to update, or rather the TextView. I have looked around the net for hours for solutions and I sort of know why its not…
Perilion
  • 43
  • 1
  • 4
2
votes
4 answers

Other ways to update UI from thread in C#

My application is heavily depended on threads to do the complex processing of very large data. The UI needs to be updated as the processing is being done. I know and tried to used BackgroundWorker's OnProgressChanged and RunWorkerCompleted methods…
Vinod Maurya
  • 4,167
  • 11
  • 50
  • 81
2
votes
4 answers

Update current activity view behind/while showing loading dialog

I have an app in which the app flow is different from Android standard: Standard: Pressing a button on activity A and showing loading on this activity while loading the data and building the views of activity B and only then show the next…
neteinstein
  • 17,529
  • 11
  • 93
  • 123
2
votes
5 answers

Where is the main thread in android app?

I have written a game (I'll give it the name "Gamer") in which I have the following general structure (the code has been much simplified): public class Gamer extends Activity implements View.OnClickListener { public void onCreate(Bundle…
Mick
  • 8,284
  • 22
  • 81
  • 173