You need to take reference of System.DirectoryService. Then use the following code
string appPoolPath = "IIS://localhost/W3SVC/AppPools/myapppool";
var appPool = new DirectoryEntry(appPoolPath);
appPool.Invoke("Start", null);
appPool.Invoke("Stop", null);
appPool.Invoke("Recycle", null);
Just remember that administrative permission is needed to execute this code.