Esempio n. 1
0
        internal void AddAsyncRunBack(AsyncRun asyncalls, long id)
        {
            AsyncRunDiy.AddOrUpdate(id, asyncalls, (a, b) => asyncalls);

            if (IsCheckAsyncTimeOut)
            {
                KeyValuePair <long, DateTime> tot = new KeyValuePair <long, DateTime>(id, DateTime.Now.AddMilliseconds(MillisecondsTimeout));
                AsyncWaitTimeOut.Add(tot);
            }
        }
Esempio n. 2
0
 public void Close()
 {
     IsClose = true;
     AsyncWaitTimeOut.Clear();
     ClientManager.Close();
     Module.ModuleDiy.Clear();
     AsyncRunDiy.Clear();
     CallBackDiy.Clear();
     AsyncCallDiy.Clear();
     SyncWaitDic.Clear();
     FodyDir.Clear();
     Container.Dispose();
 }
Esempio n. 3
0
        private void SetReturnValue(ReturnResult result)
        {
            long idx = result.Id;

            if (CallBackDiy.ContainsKey(idx))
            {
                AsyncCalls call;

                if (CallBackDiy.TryRemove(result.Id, out call))
                {
                    try
                    {
                        call.SetRet(result);
                    }
                    catch (Exception er)
                    {
                        LogAction.Log(LogType.Err, "CMD:" + call.Cmd + " ERROR:\r\n" + er.Message);
                    }
                }
            }
            else if (AsyncRunDiy.ContainsKey(idx))
            {
                AsyncRun call;

                if (AsyncRunDiy.TryRemove(result.Id, out call))
                {
                    try
                    {
                        call.SetRet(result);
                    }
                    catch (Exception er)
                    {
                        LogAction.Log(LogType.Err, "AsynRun ID:" + result.Id + " ERROR:\r\n" + er.Message);
                    }
                }
            }
            else if (SyncWaitDic.ContainsKey(idx))
            {
                ReturnEventWaitHandle wait;

                if (SyncWaitDic.TryRemove(result.Id, out wait))
                {
                    wait.Set(result);
                }
            }
            else
            {
                throw new InvalidOperationException("not call the Id");
            }
        }
Esempio n. 4
0
        private void SetReturnValue(Result result)
        {
            long idx = result.Id;

            if (CallBackDiy.ContainsKey(idx))
            {
                if (CallBackDiy.TryRemove(result.Id, out AsyncCalls call))
                {
                    try
                    {
                        call.SetRes(result);
                    }
                    catch (Exception er)
                    {
                        if (PushException(new SetResultException(er.Message, (int)ErrorTag.SetErr, er)))
                        {
                            Log.Error($"CMD:{call.Cmd} ERROR:\r\n{er.Message}");
                        }
                    }
                }
            }
            else if (AsyncRunDiy.ContainsKey(idx))
            {
                if (AsyncRunDiy.TryRemove(result.Id, out AsyncRun call))
                {
                    try
                    {
                        call.SetRet(result);
                    }
                    catch (Exception er)
                    {
                        if (PushException(new SetResultException(er.Message, (int)ErrorTag.SetErr, er)))
                        {
                            Log.Error($"AsynRun ID:{result.Id} ERROR:\r\n{er.Message}");
                        }
                    }
                }
            }
            else if (SyncWaitDic.ContainsKey(idx))
            {
                if (SyncWaitDic.TryRemove(result.Id, out ReturnEventWaitHandle wait))
                {
                    wait.Set(result);
                }
            }
        }
Esempio n. 5
0
        private async void CheckAsyncTimeOut()
        {
            while (true)
            {
                if (IsClose)
                {
                    break;
                }

                int timeSleep = 1;

                try
                {
                    if (!IsCheckAsyncTimeOut || AsyncWaitTimeOut.Count == 0)
                    {
                        timeSleep = 1000;
                    }
                    else
                    {
                        var res = AsyncWaitTimeOut.FindAll(p => p.Value < DateTime.Now);

                        if (res.Count == 0)
                        {
                            timeSleep = 200;
                        }
                        else
                        {
                            foreach (var item in res)
                            {
                                long id = item.Key;
                                if (AsyncRunDiy.ContainsKey(id))
                                {
                                    if (AsyncRunDiy.TryRemove(id, out AsyncRun value))
                                    {
                                        await Task.Run(() =>
                                        {
                                            try
                                            {
                                                value.SetRet(GetExceptionResult("run time out", (int)ErrorTag.TimeOut, id));
                                            }
                                            catch (Exception er)
                                            {
                                                if (PushException(new SetResultException(er.Message, (int)ErrorTag.SetErr, er)))
                                                {
                                                    Log.Error($"Id:{value.Id} ERROR:\r\n{er.Message}");
                                                }
                                            }
                                        });
                                    }
                                }

                                AsyncWaitTimeOut.Remove(item);
                            }
                        }
                    }
                }
                catch (Exception er)
                {
                    if (PushException(er))
                    {
                        Log.Error($"ERROR:\r\n{er.ToString()}");
                    }
                }
                finally
                {
                    await Task.Delay(timeSleep);
                }
            }
        }
Esempio n. 6
0
 internal void AddAsyncRunBack(AsyncRun asyncalls, long id)
 {
     AsyncRunDiy.AddOrUpdate(id, asyncalls, (a, b) => asyncalls);
 }