Do you mean HTTP request made by a schedule task? Or to detect whether current code is executed by a schedule task (without HTTP requests)? In the first case you have to add some headers. In the second case load the current customer ("CurrentCustomer" property of "IWorkContext") and see its "SystemName" property. It should be set to SystemCustomerNames.BackgroundTask ("BackgroundTask")