Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » NSThread.isMainThread(isMainThread returns false for main thread)
NSThread.isMainThread [message #630477] Sun, 03 October 2010 02:40 Go to next message
Eclipse UserFriend
Hi,

I am an experienced win32 developer but very new to MACOS. I am trying to create a very simple SWT app to learn MACOS and I am stumped at the very start. I have the following code;

public static void main(String[] args) {
    if (NSThread.isMainThread()) {
        System.out.println("BEING MAIN THREAD");
    } else {
        System.out.println("NOT IN MAIN THREAD");
   }
}


This code prints "NOT IN MAIN THREAD". Any ideas why? What am I missing. If I run it in the debugger it's definitely the main (and only) thread.

Thanks for your help
Mark
Re: NSThread.isMainThread [message #630550 is a reply to message #630477] Mon, 04 October 2010 01:06 Go to previous messageGo to next message
Eclipse UserFriend
On 03/10/10 12:10 PM, Ozzie wrote:
> I am an experienced win32 developer but very new to MACOS. I am trying
> to create a very simple SWT app to learn MACOS and I am stumped at the
> very start. I have the following code;
>
>
> public static void main(String[] args) {
> if (NSThread.isMainThread()) {
> System.out.println("BEING MAIN THREAD");
> } else {
> System.out.println("NOT IN MAIN THREAD");
> }
> }
>
>
> This code prints "NOT IN MAIN THREAD". Any ideas why? What am I missing.
> If I run it in the debugger it's definitely the main (and only) thread.

It prints "BEING MAIN THREAD" for me. BTW, if you want to learn MacOS
why are you using SWT? You could try XCode and Cocoa directly

--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: NSThread.isMainThread [message #756139 is a reply to message #630550] Fri, 11 November 2011 03:32 Go to previous messageGo to next message
Eclipse UserFriend
Answering a question with another question is not a very useful response! I see a similar result. I have an SWT application which runs fine on Windows and Unix but on Mac it complains about Display not being created on the main thread.
Re: NSThread.isMainThread [message #756208 is a reply to message #756139] Fri, 11 November 2011 08:37 Go to previous message
Eclipse UserFriend
On Mac, you need to launch the SWT application with the -XstartOnFirstThread VM option.
Previous Topic:SWT_AWT, Swing Frame to receive CTRL+C
Next Topic:How to call a section in SWT?
Goto Forum:
  


Current Time: Wed Jul 23 02:12:45 EDT 2025

Powered by FUDForum. Page generated in 0.04255 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top