Esempio n. 1
0
        public static void Initialize(ScanSense sense)
        {
            try
            {
                ScanSensitivity = sense;

                EventsManager = new KAVE.BaseEngine.KavprotEvents();
                AsyncInvoke inv = new AsyncInvoke(VirusReportService.Initialize);
                inv.BeginInvoke(null, null);

                // load scanners
                AsyncInvoke sinv = new AsyncInvoke(Init);
                sinv.BeginInvoke(null, null);
                if (SettingsManager.TurboMode)
                {
                    AsyncInvoke ssinv = new AsyncInvoke(VDB.Initialize);
                    ssinv.BeginInvoke(null, null);
                }
                else
                {
                    VDB.Initialize();
                }
            }
            catch (Exception ex)
            {
                AntiCrash.LogException(ex);
            }
        }
Esempio n. 2
0
        private static void DelegateCallback(IAsyncResult iresult)
        {
            Console.WriteLine($"Getting callback on Thread {Thread.CurrentThread.ManagedThreadId}");
            AsyncResult asyncResult = (AsyncResult)iresult;
            AsyncInvoke method1     = (AsyncInvoke)asyncResult.AsyncDelegate;

            int retVal = method1.EndInvoke(asyncResult);//在回调委托里面EndInvoke

            Console.WriteLine($"retVal (CallBack):{retVal}");
        }
Esempio n. 3
0
        static void Action()
        {
            while (true)
            {
                AsyncInvoke asyncInvoke = new AsyncInvoke(Delegate);
                asyncInvoke.Invoke();

                GC.Collect();
                Thread.Sleep(10 * 1000);
            }
        }
Esempio n. 4
0
        public void CallbackAsyncDelete()
        {
            //回调委托
            AsyncCallback callBack = DelegateCallback;
            //自定义委托
            AsyncInvoke method1 = TestAsyncInvoke.Method1;

            Console.WriteLine($"Calling BeginInvike on Thread {Thread.CurrentThread.ManagedThreadId}");
            IAsyncResult asyncResult = method1.BeginInvoke(callBack, method1);//以BeginInvoke开始,第二个参数表示状态对象

            return;
        }
            public void CallbackAsyncDelegate()
            {
                AsyncCallback callBack = DelegateCallback;

                AsyncInvoke method1 = TestAsyncInvoke.Method1;

                Console.WriteLine(
                    $"Calling BeginInvoke on Thread {Thread.CurrentThread.ManagedThreadId}");
                IAsyncResult asyncResult = method1.BeginInvoke(callBack, method1);

                // No need to poll or use the WaitOne method here, so return to the calling method.
                return;
            }
Esempio n. 6
0
        public void PollAsyncDelegate()
        {
            AsyncInvoke  MI = new AsyncInvoke(TestAsyncInvoke.Method1);
            IAsyncResult AR = MI.BeginInvoke(null, null);

            while (!AR.IsCompleted)
            {
                System.Threading.Thread.Sleep(100);
                Console.WriteLine('.');
            }
            Console.WriteLine("Finished Polling");

            try
            {
                int retVal = MI.EndInvoke(AR);
                Console.WriteLine("RetVal (Polling): " + retVal);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Esempio n. 7
0
 private void Elapsed(object sender, ElapsedEventArgs e)
 {
     if (((TimeSpan)(DateTime.Now - this.lastMinute)).TotalSeconds > 60)
     {
         this.lastMinute = DateTime.Now;
         AsyncInvoke.Fire(this.Minute, this, EventArgs.Empty);
     }
     if (((TimeSpan)(DateTime.Now - this.lastHour)).TotalSeconds > 60 * 60)
     {
         this.lastHour = DateTime.Now;
         AsyncInvoke.Fire(this.Hour, this, EventArgs.Empty);
     }
     if (((TimeSpan)(DateTime.Now - this.lastEightHours)).TotalSeconds > 60 * 60 * 8)
     {
         this.lastEightHours = DateTime.Now;
         AsyncInvoke.Fire(this.EightHours, this, EventArgs.Empty);
     }
     if (((TimeSpan)(DateTime.Now - this.lastTwentyFourHours)).TotalSeconds > 60 * 60 * 24)
     {
         this.lastTwentyFourHours = DateTime.Now;
         AsyncInvoke.Fire(this.TwentyFourHours, this, EventArgs.Empty);
     }
 }
Esempio n. 8
0
        public void ProcessQueue()
        {
            if (_syncThread != Thread.CurrentThread)
            {
                throw new Exception("must be called from the same thread it was created on");
            }

            AsyncInvoke data = null;

            while (true)
            {
                lock (_toExecuteQueue)
                {
                    if (_toExecuteQueue.Count == 0)
                    {
                        break;
                    }

                    data = _toExecuteQueue.Dequeue();
                }

                data.Invoke();
            }
        }
Esempio n. 9
0
        public static void Initialize(KavprotInitialization init)
        {
            try
            {
                // init settings
                SettingsManager.Initialize();
                if (SettingsManager.TurboMode)
                {
                    AsyncInvoke ainv = new AsyncInvoke(KavprotVoice.Initialize);
                    ainv.BeginInvoke(null, null);
                    // Activation.Initialize();
                    //if (!Activation.Expired)
                    //{
                    if (init == KavprotInitialization.Full)
                    {
                        // init monitors

                        AsyncInvoke inv = new AsyncInvoke(InitMonitors);
                        inv.BeginInvoke(null, null);


                        // init engine
                        AVEngine.Initialize(SettingsManager.Scansense);


                        if (SettingsManager.KavprotRemoteControl)
                        {
                            AsyncInvoke dinv = new AsyncInvoke(KavprotRemoteControl.Init);
                            dinv.BeginInvoke(null, null);

                            AsyncInvoke tinv = new AsyncInvoke(KavprotRemoteControl.ReceiveDataFromMobile);
                            tinv.BeginInvoke(null, null);
                        }

                        AntivirusState.SetProtection(true);
                    }
                    else
                    {
                        // init engine
                        AVEngine.Initialize(SettingsManager.Scansense);
                    }
                    //}
                    //else
                    //{
                    //    MessageBox.Show("Kavprot will be closed after you click ok", "Activation", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    //    ShutDown();
                    //}
                }
                else
                {
                    KavprotVoice.Initialize();

                    //Activation.Initialize();
                    //if (!Activation.Expired)
                    //{
                    if (init == KavprotInitialization.Full)
                    {
                        // init monitors
                        InitMonitors();
                        // init engine
                        AVEngine.Initialize(SettingsManager.Scansense);
                        if (SettingsManager.KavprotRemoteControl)
                        {
                            KavprotRemoteControl.Init();
                            AsyncInvoke inv = new AsyncInvoke(KavprotRemoteControl.ReceiveDataFromMobile);
                            inv.BeginInvoke(null, null);
                        }

                        AntivirusState.SetProtection(true);
                    }
                    else
                    {
                        // init engine
                        AVEngine.Initialize(SettingsManager.Scansense);
                    }
                    //}
                    //else
                    //{
                    //    MessageBox.Show("Kavprot will be closed after you click ok", "Activation", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    //    ShutDown();
                    //}
                }
            }
            catch
            {
            }
        }
Esempio n. 10
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            try
            {
                if (channel == null || !channel.Open)
                {
                    channel = AsyncInvoke.RunSync(() => bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(Host), Port)));
                }
            }
            catch (Exception ero)
            {
                throw new Exception("连接服务端失败:" + ero);
            }
            var id     = Guid.NewGuid().ToString();
            var method = ServiceType.GetMethod(binder.Name);

            allWaits.Add(id);
            var request = new RequestMessage
            {
                MsgId   = id,
                Service = ServiceName,
                Method  = binder.Name,
                Token   = Token
            };
            var dic     = new Dictionary <string, object>();
            var allArgs = method.GetParameters();
            var outs    = new Dictionary <string, object>();

            for (int i = 0; i < allArgs.Length; i++)
            {
                var p = allArgs[i];
                dic.Add(p.Name, args[i]);
                if (p.Attributes == ParameterAttributes.Out)
                {
                    outs.Add(p.Name, i);
                }
            }
            request.Args = dic;
            channel.WriteAndFlushAsync(request.ToBuffer());
            //等待返回
            var response = allWaits.Wait(id).Response;

            if (response == null)
            {
                throw new Exception("请求超时未响应");
            }
            if (!response.Success)
            {
                throw new Exception($"服务端处理错误:{response.Msg}");
            }
            var returnType = method.ReturnType;

            if (response.Outs != null && response.Outs.Count > 0)
            {
                foreach (var kv in response.Outs)
                {
                    var find = outs[kv.Key];
                    args[(int)find] = kv.Value;
                }
            }
            if (returnType == typeof(void))
            {
                result = null;
                return(true);
            }
            result = response.GetData(returnType);
            return(true);
        }
Esempio n. 11
0
 /// <summary>
 /// POST内容,并返回跳转后的URL
 /// </summary>
 /// <param name="url"></param>
 /// <param name="data"></param>
 /// <param name="now_url"></param>
 /// <returns></returns>
 public string SendData(string url, string method, string data)
 {
     return(AsyncInvoke.RunSync(() => SendDataAsync(url, method, data)));
 }
Esempio n. 12
0
 public Window1()
 {
     InitializeComponent();
     asyncInvoke = new AsyncInvoke();
 }