bool isInMainThread() Method?

I need to know if the current thread is the ‘main’ thread.
like…

public static bool isInMainThread()
{
     // What goes here??
}

This is so I can have a loggin function that
uses Time.time.ToString() which can only be used in the main thread, and not use Time.time if not in the mian thread.

? I dont get what you want to do here …
If you have created a thread on your own than this thread will never be “in the main thread”.

Right…everything is already in the main thread by default. If you do your own threads then you already know if you’re using the main thread or not and thus don’t need any function to tell you.

–Eric

Yeah, right, whatever.
Anyway, if the OP or any visitor is still interested, this is how I do it:
I do this in a static class called App:

using System.Threading;

public static class App
{
    public static int unityThreadId = -1;

    public static bool IsUnityThread()
    {
        return (Thread.CurrentThread.ManagedThreadId == unityThreadId);
    }
}

So right at the very beginning of your game, in the Awake() of a global component or something, you do something like:

App.unityThreadId = Thread.CurrentThread.ManagedThreadId;

then you can just call App.IsUnityThread() anytime.
Beware! This will not work in the Editor! For some strange reason I don’t understand, ManagedThreadId always returns 1, no matter what thread your in, when called inside the editor. It will work on builds no problem, though.