Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Threading.Thread replacement in UWP / Windows 10 mobile

In UWP, how can I access the thread object? I want to change the name of the main thread and additional thread that I will manage.

I also want to check if the current thread is the main thread afterwards.

I'm targeting to windows 10 mobile. The following code example works for desktop, but not for phone (getting 'System.DllNotFoundException'):

[DllImport("kernel32.dll")]
static extern IntPtr GetCurrentThread();

Thanks.

like image 561
Ido Sofi Avatar asked Oct 19 '25 21:10

Ido Sofi


2 Answers

You should use Tasks instead of threads. https://msdn.microsoft.com/en-us/library/system.threading.tasks.task%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

As about renaming of threads, can you tell me why do you need to rename main thread and other threads!?

like image 87
Konstantin Adamov Avatar answered Oct 22 '25 06:10

Konstantin Adamov


You should try System.Environment.CurrentManagedThreadId (yes, you can get only current thread id) https://msdn.microsoft.com/en-us/library/system.environment.currentmanagedthreadid(v=vs.110).aspx

like image 21
Yury Schkatula Avatar answered Oct 22 '25 04:10

Yury Schkatula



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!