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

  
InnerException:
       HResult=-2146233079
       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();
                _settingService.SaveSetting(orderSettings);
                _settingService.ClearCache();
            }
        }

        public void Execute()
        {
            Thread thread = new Thread(UpdateRefreshToken);
            thread.Start();
            Thread.Sleep(5000);
        }


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

Please login or register
to vote for this post.

(click on this box to dismiss)