Posted: July 17, 2017 at 4:05 AM Quote #190146
I want to run an asynchronous method in a schedule task, but I am getting errors

       Message=There is already an open DataReader associated with this Command which must be closed first.

So, here I am providing my code  

        private readonly IStoreContext _storeContext;
        private readonly ISettingService _settingService;

        public TradeGeckoRefreshToken(IStoreContext storeContext, ISettingService settingService)
            _storeContext = storeContext;
            _settingService = settingService;

        public async void UpdateRefreshToken()
            var orderSettings = _settingService.LoadSetting<OrderSettings>();
            Task<JObject> returnObject = TradeGeckoHelperMethods.RefreshAccessToken(orderSettings.TradeGeckoApplicationId, orderSettings.TradeGeckoSecretId, orderSettings.TradeGeckoCallBackUrl, orderSettings.TradeGeckoRefreshToken);
            JObject refresheObject = await returnObject;

            if (refresheObject[JsonKeys.AccessToken] != null)
                orderSettings.TradeGeckoAccessToken = refresheObject[JsonKeys.AccessToken].ToString();
                orderSettings.TradeGeckoRefreshToken = refresheObject[JsonKeys.RefreshToken].ToString();

        public void Execute()
            Thread thread = new Thread(UpdateRefreshToken);

But running this schedule task product mentioned error.
This post/answer is useful
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)