The following method always prints “Process Thread Count = 0” to the console:
void Start()
{
System.Diagnostics.Process process =
System.Diagnostics.Process.GetCurrentProcess();
process.Refresh();
UnityEngine.Debug.Log("Process Thread Count = " + process.Threads.Count);
}
That’s weird even if I wouldn’t start separate threads but I do. Is this a bug? Or am I doing something wrong? I also asked this question on stackoverflow but I didn’t get an answer yet: Current process without threads?
I am using Unity 4.5.1f3 (Mono 2.0.50727.1433)
Can someone at least try this piece of code and tell me if it works for him/her?
(The one time I did research into Unity and threads, I learned that Unity cannot do multi-threading… I hope that answers part of your question?)
Well, if you mean that you can’t use Unity’s API from threads other than the main thread, you’re right. However, you can use System.Threading.Threads or System.Threading.ThreadPool if you don’t make them call Unity methods!
Here you can see the workload for my CPUs caused by a Unity application that creates 1000 threads that are running some heavy duty calculations (just a loop with several sqrt calls, i.e. no Unity methods):
So, it is possible! The question is why does process.Threads.Count return zero?
Sbizz
January 20, 2015, 12:33pm
5
It returns 0 because you didn’t create any thread ?
I don’t see any bugs here.
Even if I do not create threads on my own, as far as I know there should always be at least one thread already there: the main thread!
Apart from that: I did create threads! The post above your answer mentions 1000 threads but nevertheless process.Threads.Count prints zero!
Sbizz
January 20, 2015, 12:51pm
7
Hmm.
Okay, I was thinking that the method would count the number of thread created by you . But I guess it doesn’t.
So I don’t know, but interesting question. Let see if someone has the answer!
I’ve created a Bug Report about this issue, now. I will keep you posted.
1 Like
A small addition: Now I’ve tested this issue with the latest Unity version, too. The problem still exists. Should I create another bug report or is there a way to update my last report?
Okay, it’s a bug! I’ve created a bug report some days ago and today I got the following answer:
“[…] We have fixed this and [the] problem will not appear in the next major version. […]”
Now I’m curious what the next major version will be.
2 Likes
s_guy
March 24, 2016, 10:35pm
11
it still doesn’t work in Unity 5.3
Just adding to this; I also have this issue.
I’ve created another bug report. I will keep you posted.
I’ve got a first answer:
It is not implemented in our Mono.
[MonoTODO]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden), Browsable (false)]
[MonitoringDescription (“The number of threads of this process.”)]
public ProcessThreadCollection Threads {
get {
return ProcessThreadCollection.GetEmpty ();
}
}
My next question was, if it will be implemented in the next version of Unity. I will keep you posted again.
spvn
May 26, 2017, 8:46am
17
Has this bug really not been solved after 2 years? Is it an issue with Mono or something? Is there no way to access process.Threads at all in unity?
Bug still applies to the version 2017.1.0.9b
Any news on the bug report?
Can you link to it here?
ThreadPool.GetAvailableThreads is also not supported.
Guess this explains why people are rolling their own thread pools.