IOrganizationService _CrmService = GetCRMService(); //a function to return ms crm service object
SetStateRequest _SetStateReq = new SetStateRequest();
//provide entity details
SetStateReq.EntityMoniker = new EntityReference(“your custom entity logical name”, new Guid(“CustomEntityID”));
// Set the State and Status OptionSet Values to completed.
SetStateReq.State = new OptionSetValue(1);
SetStateReq.Status = new OptionSetValue(2);
// call execute message by passing request object
SetStateResponse _SetStateResp = (SetStateResponse)_CrmService.Execute(SetStateReq);
}