How do I use Texture2d in other thread?

I made ScreenShot function in my app, and actually it works. But in this function, if the screen resolution is large, this inserts a little delay (within one second). So that I tried to use System.Threading.Thread() and call GenerateScreenShot() in thread. But faced below error related to Texture2D.

So are there other solution in unity? My app uses USB camera, and delay isn’t allowed. Please let me know…

void GenerateScreenShot(string filename_) {
	int sw = Screen.width;
	int sh = Screen.height;
	Texture2D tex = new Texture2D(sw, sh, TextureFormat.RGB24, false);
	tex.ReadPixels(new Rect(0.0f, 0.0f, sw, sh), 0, 0);
	byte[] bytes = tex.EncodeToPNG();
	string url =  Application.dataPath.ToString() + filename_;
	File.WriteAllBytes(url, bytes);

error in thread

UnityEngine.Texture2D:Internal_Create(Texture2D, Int32, Int32, TextureFormat, Boolean)
UnityEngine.Texture2D:.ctor(Int32, Int32, TextureFormat, Boolean) (at C:\BuildAgent\work\842f9557127e852\Runtime\ExportGenerated\Editor\Graphics.cs:506)
MyScript:GenerateScreenShot(String) (at Assets\Scripts\MyScript.cs:102)
MyScript:start() (at Assets\Scripts\MyScript.cs:156)

You can call thread safe .NET methods from your code, but unfortunately Unity doesn’t allow you to multi-thread its own internal methods… such as Texture2D.ReadPixels(), which is probably why you have that error.

ReadPixels copies rendered image data from the graphics buffer into the texture. This can only happen on the render-thread (as OpenGL, and probably DirectX as well, are inherently single threaded) and it can only be done between two frames.

If you are lucky, you should be able to move the “EncodeToPNG” method to a different thread, but never the “ReadPixels” call.

Alternatively, you may be able to use Application.CaptureScreenshot instead.