Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Device.StartTimer vs System.Threading.Timer in Xamarin.Forms [closed]

What's a benefits or drawbacks of using Device.StartTimer vs System.Threading.Timer?

Both are firing on background threads, both are cross-platform and netstandard2 compatible. System.Threading.Timer has a bonus points of being non-Xamarin specific.

What should I use and when?

  • Device.StartTimer use native APIs.
  • According to github.com/mono, System.Threading.Timer seems to use dedicated thread for all timers. Am I right, or do Xamarin use another implementation?
like image 424
Leotsarev Avatar asked Jan 01 '23 14:01

Leotsarev


1 Answers

Official answer from Xamarin documentation team: https://github.com/MicrosoftDocs/xamarin-docs/issues/2243#issuecomment-543608668

Use either.

Device.StartTimer was implemented long before .NET Standard came along, and in those days the Timer class was unavailable to PCL projects. Now that the Timer class is available, there's no advantage/need to use Device.StartTimer. But that API won't vanish, because there will be older projects that still rely on it.

like image 96
Leotsarev Avatar answered Jan 09 '23 11:01

Leotsarev