Results 1 to 6 of 6
- 08-26-2012, 08:37 AM #1
Calling a method on mainthread when another thread finishes
Guys, I have a problem. I am currently working on a Email client in QT Jambi just for learning. The GUI of QT only works on the main thread.
My main problem is that while I fetch the emails from the server, I perform this operation on a different thread to avoid blocking of the UI.
but when the thread finishes fetching the mails I want to display all of them as a list on a Table. this Table can only be accessed by the main thread only, otherwise the program will crash.
So, how can I call a method on main thread when the other thread finishes or I can notify the main thread to call that method.
Plz help...
- 08-26-2012, 03:25 PM #2
Re: Calling a method on mainthread when another thread finishes
Can you make a small, simple program that compiles, executes and shows the problem? Use a dummy method to simulate getting mail on another thread, perhaps with calls to sleep() to pass time.
What is the "main" thread doing while the background task is running? Is the "main" thread the same as the Swing EDT?If you don't understand my response, don't ignore it, ask a question.
-
Re: Calling a method on mainthread when another thread finishes
- 08-27-2012, 06:54 PM #4
Re: Calling a method on mainthread when another thread finishes
By main thread I mean the original thread on which the actual program execution starts. In other words, the thread on which main(String[]args) runs.
While the background task runs, main thread allows the application to respond to the user's action. Otherwise the application will hang while the mail fetching is underway.
I need a way to know when the background task ends and then I'll refresh the User interface. This refreshing of UI must be done on the main thread otherwise the app will crash.
-
Re: Calling a method on mainthread when another thread finishes
- 08-27-2012, 07:13 PM #6
Re: Calling a method on mainthread when another thread finishes
Not sure how you are using the thread that the JVM uses to call the main() method. In many programs, the main() method creates the GUI, does some init work and returns. That original thread is not executing anywhere in the program after main() exits.
When the user creates an event, the JVM calls a listener on another thread.
What is the thread used when the main() method is initially called by the JVM doing while the background task is executing?If you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
Block thread until callback method has been called by other thread
By James2000 in forum Threads and SynchronizationReplies: 4Last Post: 05-11-2012, 10:46 PM -
Re-iterate Thread execution after its execution finishes.
By TurtleRock in forum New To JavaReplies: 10Last Post: 11-29-2010, 03:02 PM -
Thread problem, calling method in run method
By majk in forum Threads and SynchronizationReplies: 4Last Post: 09-27-2010, 12:40 PM -
Trigger main thread method from secondary thread?
By DigitalMan in forum Threads and SynchronizationReplies: 8Last Post: 01-26-2010, 03:13 AM -
Calling a method in a different class from within a method problem
By CirKuT in forum New To JavaReplies: 29Last Post: 09-25-2008, 08:55 PM
Bookmarks