Yes, you can use 10w40 for chainsaw bar oil but it’s not the very best oil for the chain. Basically the stihl and Husqvarna type chainsaw use much thicker and that is vegetable based.
This is much better for you to use that oil which is recommended by the brand like stihl brand recommends oil on its site in which best is woodcutter bar and chain oil.
You also search related brands for better results for your machine.

Co-Founder Cord To Cordless
Adan grew up in farmland and learned many things at an earlier age and works in more than 6+ places with different works to gain experience in multiple fields. Currently doing shop projects.
Adan loves to share experiences to build more creativity in your mind.