Beispiel #1
0
        public static void ForEach <T>(IEnumerable <T> enumerable, ForEachDelegate <T> action)
        {
            IEnumerator <T> enumerator = enumerable.GetEnumerator();
            object          oLock      = new object();

            ProcessDelegate process = delegate() {
                while (true)
                {
                    T current;

                    lock (oLock) {
                        if (!enumerator.MoveNext())
                        {
                            return;
                        }
                        current = enumerator.Current;
                    }

                    action(current);
                }
            };

            int threads = Environment.ProcessorCount;

            WaitHandle[] handles = new WaitHandle[threads];
            for (int i = 0; i < threads; i++)
            {
                handles[i] = process.BeginInvoke(ProcessCallback, process).AsyncWaitHandle;
            }
            WaitHandle.WaitAll(handles);
        }
Beispiel #2
0
        public OcrProgressDialog(bool allowProgress, string title, ProcessDelegate del, Dictionary <string, object> args)
        {
            InitializeComponent();

            Text      = title;
            _delegate = del;
            _args     = args;

            _allowProgress = allowProgress;

            if (_allowProgress)
            {
                _panel.BorderStyle = BorderStyle.None;
            }
            else
            {
                // Hide the border and cancel button
                _panel.BorderStyle    = BorderStyle.FixedSingle;
                FormBorderStyle       = FormBorderStyle.None;
                _cancelButton.Visible = false;
                _cancelButton.Enabled = false;

                // Use Marquee progress style
                _progressBar.Style = ProgressBarStyle.Marquee;
            }

            _isWorking = true;
        }
Beispiel #3
0
 private void Start_Click(object sender, RoutedEventArgs e)
 {
     //processName = ProcessName.Text;
     //killCyle = ScanCycle.Text;
     //backgroundKiller_Initial();
     //backgroundKiller.RunWorkerAsync();
     this.Close();
     while (true)
     {
         ProcessDelegate processDelegate = new ProcessDelegate(Killer);
         this.Dispatcher.Invoke(processDelegate);
         if (ScanCycle.Text.Equals(""))
         {
             Thread.Sleep(3000);
         }
         else if (ScanCycle.Text.Equals("0"))
         {
             Thread.Sleep(100);
         }
         else
         {
             Thread.Sleep(Convert.ToInt32(ScanCycle.Text) * 1000);
         }
     }
 }
        static void Main(string[] args)
        {
            //Test overloads
            int mainVal = 10;
            Console.WriteLine("In Main, value now {0}", mainVal);
            OverloadTest(mainVal);
            Console.WriteLine("In Main, value now {0}", mainVal);
            OverloadTest(ref mainVal);
            Console.WriteLine("In Main, value now {0}", mainVal);

            //test delegates
            ProcessDelegate testDelegate;
            Console.WriteLine("Please enter two numbers, separated by a comma:");

            String input = Console.ReadLine();
            String[] numbers = input.Split(',');
            //Assume correct formatting for now
            double temp1 = Convert.ToDouble(numbers[0]);
            double temp2 = Convert.ToDouble(numbers[1]);

            testDelegate = new ProcessDelegate(Multiply);
            double temp3 = testDelegate(temp1, temp2);
            Console.WriteLine("First result of testDelegate is {0}", temp3);

            testDelegate = new ProcessDelegate(Divide);
            temp3 = testDelegate(temp1, temp2);
            Console.WriteLine("Second result of testDelegate is {0}", temp3);

            //wait for the user to press a key
            Console.ReadKey();
        }
Beispiel #5
0
        // HTTP DOWNLOAD 异步
        static public HttpRequester Download(string url, int range, string savePath, ProcessDelegate onProcess = null, RespDelegate onResponse = null)
        {
            HttpRequester reqInfo = new HttpRequester(url, range.ToString(), "GETF", savePath, onProcess, onResponse);

            reqInfo.Start();
            return(reqInfo);
        }
Beispiel #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // 声明委托变量
            ProcessDelegate process;
            Console.WriteLine("请输入用逗号分隔的两个数字:");
            string input = Console.ReadLine();
            int commaPos = input.IndexOf(',');
            double param1 = Convert.ToDouble(input.Substring(0, commaPos));
            double param2 = Convert.ToDouble(input.Substring(commaPos + 1, input.Length - commaPos - 1));

            Console.WriteLine("输入M乘法D除法");
            input = Console.ReadLine();

            // 初始化委托变量
            if (input == "M")
                process = new ProcessDelegate(Multiply);
            //注释:此处也可以写process = Multiply
            else
                process = new ProcessDelegate(Divide);

            // 使用委托调用函数
            double result = process(param1, param2);
            Console.WriteLine("结果:{0}", result);
            Console.ReadKey();
        }
Beispiel #7
0
        public static void For(int start, int end, Action <int> action)
        {
#if SILVERLIGHT
            object          oLock   = new object();
            ProcessDelegate process = delegate() {
                for (int n = 0; n < end;)
                {
                    lock (oLock) {
                        n = start;
                        start++;
                    }

                    action(n);
                }
            };

            int          threads = Environment.ProcessorCount;
            WaitHandle[] handles = new WaitHandle[threads];
            for (int i = 0; i < threads; i++)
            {
                handles[i] = new ManualResetEvent(false);
                ThreadPool.QueueUserWorkItem(delegate(object state)
                {
                    process();
                    ((ManualResetEvent)state).Set();
                }, handles[i]);
            }
            WaitHandle.WaitAll(handles);
#else
            Parallel.For(start, end, action);
#endif
        }
Beispiel #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // 声明委托变量
            ProcessDelegate process;
            Console.WriteLine("请输入用逗号分隔的两个数字:");
            string input = Console.ReadLine();
            int commaPos = input.IndexOf(',');
            double param1 = Convert.ToDouble(input.Substring(0, commaPos));
            double param2 = Convert.ToDouble(input.Substring(commaPos + 1, input.Length - commaPos - 1));

            Console.WriteLine("输入M乘法D除法");
            input = Console.ReadLine();

            // 初始化委托变量
            if (input == "M")
                process = new ProcessDelegate(Multiply);
            //注释:此处也可以写process = Multiply
            else
                process = new ProcessDelegate(Divide);

            // 使用委托调用函数
            double result = process(param1, param2);
            Console.WriteLine("结果:{0}", result);
            Console.ReadKey();
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            ProcessDelegate process; // declare a new variable of our delegate type - but dont initialise it yet - i.e. it doesn't actually contain an object yet

            WriteLine("Enter 2 numbers separated by a comma:");

            string input    = ReadLine();
            int    commaPos = input.IndexOf(',');
            double param1   = ToDouble(input.Substring(0, commaPos));
            double param2   = ToDouble(input.Substring(commaPos + 1, input.Length - commaPos - 1));

            WriteLine("Enter M to multiply or D to divide:");
            input = ReadLine().ToUpper();

            // here we create a new instance of delegate and pass it the function name that we want to use
            // think of this as saying what signature, or interface, the delegate must use, then we pass it a reference to the actual function as we initialise it.
            if (input == "M")
            {
                process = new ProcessDelegate(Multiply);
            }
            else
            {
                process = new ProcessDelegate(Divide);
            }

            // our new delegate object now has the same signature as our two functions, and when we call it, it's behaviour reflects that of the function specified at the point of initialisation.
            // even though delegates are considered variables (because their contents can change), they are treated like functions once initialised.
            WriteLine($"Result: {process(param1, param2)}");

            //although we've called process, like a function, directly above, we could pass the instance (process) into another function and call it there instead - i.e.:
            PassAndExecuteDelegate(process);

            ReadKey();
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            //get value from keyboard
            ProcessDelegate process;

            Console.WriteLine("Enter 2 numbers separated with a coma:");
            string input    = Console.ReadLine();
            int    commaPos = input.IndexOf(',');
            //definite two value
            double param1 = Convert.ToDouble(input.Substring(0, commaPos));
            double param2 = Convert.ToDouble(input.Substring(commaPos + 1, input.Length - commaPos - 1));

            //choose a function
            Console.WriteLine("Enter M to multiply or D to divide:");
            input = Console.ReadLine();
            if (input == "M")
            {
                process = new ProcessDelegate(Multiply);
            }
            else
            {
                process = new ProcessDelegate(Divide);
            }
            //print end
            Console.WriteLine($"Result: {process(param1,param2)}");
            Console.ReadKey();
        }
Beispiel #11
0
        // here is the method the delegate implements, it processes the items in the grocery list with a foreach loop

        public void ProcessItems(ProcessDelegate ProcDel)
        {
            foreach(Item item in ItemList)
            {
                ProcDel(item);
            }
        }
Beispiel #12
0
        public ClientRuntimeChannel(ClientRuntime runtime, ContractDescription contract, TimeSpan openTimeout, TimeSpan closeTimeout, IChannel contextChannel, IChannelFactory factory, MessageVersion messageVersion, EndpointAddress remoteAddress, Uri via)
        {
            this.runtime          = runtime;
            this.remote_address   = remoteAddress;
            runtime.Via           = via;
            this.contract         = contract;
            this.message_version  = messageVersion;
            default_open_timeout  = openTimeout;
            default_close_timeout = closeTimeout;
            _processDelegate      = new ProcessDelegate(Process);
            requestDelegate       = new RequestDelegate(Request);
            sendDelegate          = new SendDelegate(Send);

            // default values
            AllowInitializationUI = true;
            OperationTimeout      = TimeSpan.FromMinutes(1);

            if (contextChannel != null)
            {
                channel = contextChannel;
            }
            else
            {
                var method = factory.GetType().GetMethod("CreateChannel", new Type [] { typeof(EndpointAddress), typeof(Uri) });
                channel      = (IChannel)method.Invoke(factory, new object [] { remote_address, Via });
                this.factory = factory;
            }
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            ProcessDelegate process;

            Console.WriteLine("Enter two numbers separated with a comma:");
            string input    = Console.ReadLine();
            int    commaPos = input.IndexOf(',');
            double param1   = Convert.ToDouble(input.Substring(0, commaPos));
            double param2   = Convert.ToDouble(input.Substring(commaPos + 1, input.Length - commaPos - 1));

            Console.WriteLine("Enter M to multiply or D to divide:");
            input = Console.ReadLine();
            if (input.ToUpper() == "M")
            {
                process = new ProcessDelegate(Multiply);
            }
            //process = Multiply; //This works but it is less explicit coding
            else
            {
                process = new ProcessDelegate(Divide);
            }
            //process = Divide; //This works but it is less explicit coding
            Console.WriteLine($"Result: {process(param1, param2)}");
            Console.ReadKey();
        }
Beispiel #14
0
        // PRINTS REPORT BASED ON DELEGATE

        public void PrintReports(ListBox listBox1, ProcessDelegate proccessDelegate)
        {
            foreach (string item in ProcessGardens(proccessDelegate))
            {
                listBox1.Items.Add(item);
            }
        }
 // PRINTS REPORT BASED ON DELEGATE
 public void PrintReports(ListBox listBox1, ProcessDelegate proccessDelegate)
 {
     foreach (string item in ProcessGardens(proccessDelegate))
     {
         listBox1.Items.Add(item);
     }
 }
Beispiel #16
0
        static void Main(string[] args)
        {
            ProcessDelegate1 pd1 = new ProcessDelegate1(new Program().PorgramMethod1);

            Console.WriteLine(pd1("test1 ", "test2"));
            ProcessDelegate <string, int> pd2 = new ProcessDelegate <string, int>(new Program().ProgramMethod2);

            Console.WriteLine(pd2("text", 3));
                        //key word event
                        Test t = new Test();

            t.ProcessEvent += t_ProcessEvent1;
            t.ProcessEvent += new ProcessDelegateEvent(t_ProcessEvent2);
            Console.WriteLine(000);
            Console.WriteLine(t.Process());
                        //callback
                        Testt t1 = new Testt();
            Testt2            t2 = new Testt2();
            string            s1 = t1.Process("Text1", "Text2", t2.Process1);
            string            s2 = t1.Process("Text1", "Text2", new ProcessDelegate3(t2.Process2));
            string            s3 = t1.Process("Text1", "Text2", t2.Process3);

            Console.WriteLine(s1);
            Console.WriteLine(s2);
            Console.WriteLine(s3);
            Console.ReadKey();
        }
Beispiel #17
0
        //写入当前状态信息
        public void WriteLog(string strText)
        {
            if (richTextBox1.InvokeRequired)
            {
                ProcessDelegate OutDelegate = new ProcessDelegate(WriteLog);

                this.BeginInvoke(OutDelegate, new object[] { strText });
                return;
            }

            //如果日志超过500条,则清空
            //if (richTextBox2.Lines.Length > 500)
            //{
            //    richTextBox2.Clear();
            //}

            richTextBox1.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n");
            richTextBox1.AppendText(strText);

            if (UpdateClassPriceProc.m_UpdatePriceWorkInfo.EndFlag)
            {
                if (!chkAutoUpdate.Checked)
                {
                    button1.Enabled = true;
                    button2.Enabled = false;
                }
            }
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            ProcessDelegate process;

            Console.WriteLine("Enter 2 numbers separated with comma: ");
            string input    = Console.ReadLine();
            int    commaPos = input.IndexOf(',');

            Console.WriteLine(commaPos);
            double param1 = Convert.ToDouble(input.Substring(0, commaPos));
            double param2 = Convert.ToDouble(input.Substring(commaPos + 1, input.Length - commaPos - 1));

            Console.WriteLine(input.Length);
            Console.WriteLine(param1);
            Console.WriteLine(param2);
            Console.WriteLine("Enter M to multiply or D to divide:");
            input = Console.ReadLine();
            if (input == "M")
            {
                process = new ProcessDelegate(Multiply);
            }
            else
            {
                process = new ProcessDelegate(Divide);
            }
            Console.WriteLine($"Result: {process(param1,param2)} ");
            Console.ReadKey();
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            ProcessDelegate process;    // 委托类型声明变量

            WriteLine("Enter 2 numbers separated with a comma:");
            string input    = ReadLine();
            int    commaPos = input.IndexOf(','); // 逗号分隔前后变量
            double param1   = ToDouble(input.Substring(0, commaPos));
            double param2   = ToDouble(input.Substring(commaPos + 1, input.Length - commaPos - 1));

            WriteLine("Enter M to multiply or D to divide:");
            input = ReadLine();
            // 委托变量 = 函数;
            // 委托变量 = new ProcessDelegate(函数);
            if (input == "M")
            {
                //process = Multiply;
                process = new ProcessDelegate(Multiply);    // 初始化委托变量
            }
            else
            {
                //process = Divide;
                process = new ProcessDelegate(Divide);
            }
            WriteLine($"Result: {process(param1, param2)}");
            ReadKey();
        }
Beispiel #20
0
        public static void For(int start, int end, int chunkSize, ForDelegate action)
        {
            object oLock = new object();

            ProcessDelegate process = delegate() {
                for (int n = 0; n < end;)
                {
                    lock (oLock) {
                        n      = start;
                        start += chunkSize;
                    }

                    for (int k = 0; k < chunkSize && n < end; k++, n++)
                    {
                        action(n);
                    }
                }
            };

            int threads = Environment.ProcessorCount;

            WaitHandle[] handles = new WaitHandle[threads];
            for (int i = 0; i < threads; i++)
            {
                handles[i] = process.BeginInvoke(ProcessCallback, process).AsyncWaitHandle;
            }
            WaitHandle.WaitAll(handles);
        }
Beispiel #21
0
        internal PRemoteComponent(object wrapped)
        {
            this.wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
            if (!PPatchTools.TryGetPropertyValue(wrapped, nameof(Version), out Version
                                                 version))
            {
                throw new ArgumentException("Remote component missing Version property");
            }
            this.version = version;
            // Initialize
            var type = wrapped.GetType();

            doInitialize = type.CreateDelegate <InitializeDelegate>(nameof(PForwardedComponent.
                                                                           Initialize), wrapped, typeof(Harmony));
            if (doInitialize == null)
            {
                throw new ArgumentException("Remote component missing Initialize");
            }
            // Bootstrap
            doBootstrap = type.CreateDelegate <InitializeDelegate>(nameof(PForwardedComponent.
                                                                          Bootstrap), wrapped, typeof(Harmony));
            doPostInitialize = type.CreateDelegate <InitializeDelegate>(nameof(
                                                                            PForwardedComponent.PostInitialize), wrapped, typeof(Harmony));
            getData = type.CreateGetDelegate <object>(nameof(InstanceData), wrapped);
            setData = type.CreateSetDelegate <object>(nameof(InstanceData), wrapped);
            process = type.CreateDelegate <ProcessDelegate>(nameof(PForwardedComponent.
                                                                   Process), wrapped, typeof(uint), typeof(object));
        }
Beispiel #22
0
 public Plan()
 {
     InitializeComponent();
     Init(uiStyleManager1);
     //loadpc.Location = new System.Drawing.Point((Width - loadpc.Width) / 2, (Height - loadpc.Height) / 2);
     ProcessBarStart();
     ShowProcess = new ProcessDelegate(ProcessBarRun);
 }
Beispiel #23
0
 void ProcessAction(object sender, System.EventArgs e)
 {
     if (ProcessEvent == null)
     {
         ProcessEvent += new ProcessDelegate(t_ProcessEvent);
     }
     ProcessEvent(sender, e);
 }
Beispiel #24
0
        public Login()
        {
            InitializeComponent();
            Init(uiStyleManager1);

            ShowInfo    = new MsgInfoDelegate(MessageShowSub);
            SetStatic   = new SetStaticDelegate(SetStaticSub);
            ShowProcess = new ProcessDelegate(ProcessBarRun);
        }
 /// <summary>
 /// 处理队列中的正式数据
 /// </summary>
 /// <param name="state"></param>
 public void AcceptDataWork(object state)
 {
     while (true)
     {
         try
         {
             AcceptDataEvent.WaitOne(1);
             while (AcceptDataQue.Count > 0)
             {
                 ProcessRecord msg = null;
                 lock (AcceptDataQueLock)
                 {
                     if (AcceptDataQue.Count > 0)
                     {
                         msg = AcceptDataQue.Dequeue();
                     }
                 }
                 if (msg != null)
                 {
                     var channel = EngineContext.Current.Resolve <IChannel>(msg.CHANNEL_TYPE.ToString());
                     if (null != channel)
                     {
                         ///////////////////////补抓图片//////////////////////////////////
                         if (string.IsNullOrEmpty(msg.PicFullName))
                         {
                             var channelList  = CommHelper.GetOrgInfos(msg.CHN_CODE);
                             var cameraDevice = channelList.Where(x => x.productLine == enumProductLine.IdentificationCamera && x.autoRecognition).FirstOrDefault();
                             if (null != cameraDevice)
                             {
                                 var cameraSDK = EngineContext.Current.Resolve <ICamera>(cameraDevice.deviceType.ToString());
                                 if (null != cameraSDK)
                                 {
                                     string strPicName = string.Empty;
                                     cameraSDK.CapturePicture(cameraDevice.IP, out strPicName);
                                     msg.PicFullName = strPicName;
                                 }
                             }
                         }
                         ///////////////////////开始流程//////////////////////////////////
                         ProcessDelegate dl = new ProcessDelegate(RunProcess);
                         dl.BeginInvoke(channel, msg, null, null);
                         if (null != OnPlate)
                         {
                             OnPlate(msg);
                         }
                     }
                 }
             }
             AcceptDataEvent.Reset();
         }
         catch (Exception ex)
         {
             AcceptDataEvent.Reset();
             LogHelper.Log.Error(ex.Message, ex.InnerException);
         }
     }
 }
Beispiel #26
0
        public void Start()
        {
            ProcessDelegate proc = new ProcessDelegate(DoStart);

            m_processInfo = new Syscalls.PROCESS_INFORMATION();
            CreateProcess(null, CommandLine, InheritHandles, CreationFlags, ref m_startupInfo, out m_processInfo);
            m_running = true;
            proc.BeginInvoke(null, null);
        }
        /// <summary>
        /// Register the specified type and processDelegate.
        /// </summary>
        /// <param name='type'>
        /// Process type.
        /// </param>
        /// <param name='processDelegate'>
        /// Process delegate.
        /// </param>
        public void Register(string type, ProcessDelegate processDelegate)
        {
            if (_processDelegates.ContainsKey(type))
            {
                return;
            }

            _processDelegates[type] = processDelegate;
        }
        //returns a list of strings to report
        public List<string> ProcessGardens(ProcessDelegate processDelegate)
        {
            List<string> gardenReports = new List<string>();
            foreach (Garden garden in gardens)
            {
                gardenReports.Add(processDelegate(garden));
            }

            return gardenReports;
        }
Beispiel #29
0
        private void ShowProcessBar()
        {
            CommonProcess process = new CommonProcess(55);

            SetProcess   = new ProcessDelegate(process.SetCurrentStatus);
            CloseProcess = new ProcessCloseDelegate(process.CloseProcess);
            IsStart      = true;
            process.ShowDialog();
            process = null;
        }
Beispiel #30
0
 public ClientRuntimeChannel(System.ServiceModel.Dispatcher.ClientRuntime runtime, ContractDescription contract, TimeSpan openTimeout, TimeSpan closeTimeout, IChannel contextChannel, IChannelFactory factory, MessageVersion messageVersion, System.ServiceModel.EndpointAddress remoteAddress, Uri via)
 {
     if (runtime == null)
     {
         throw new ArgumentNullException("runtime");
     }
     if (messageVersion == null)
     {
         throw new ArgumentNullException("messageVersion");
     }
     this.runtime        = runtime;
     this.remote_address = remoteAddress;
     if (runtime.Via == null)
     {
         runtime.Via = via ?? (remote_address != null ? remote_address.Uri : null);
     }
     this.contract         = contract;
     this.message_version  = messageVersion;
     default_open_timeout  = openTimeout;
     default_close_timeout = closeTimeout;
     _processDelegate      = new ProcessDelegate(Process);
     requestDelegate       = new RequestDelegate(Request);
     sendDelegate          = new SendDelegate(Send);
     AllowInitializationUI = true;
     if (contextChannel != null)
     {
         channel = contextChannel;
     }
     else
     {
         var method = factory.GetType().GetMethod("CreateChannel", new Type[] {
             typeof(System.ServiceModel.EndpointAddress),
             typeof(Uri)
         });
         try
         {
             channel = (IChannel)method.Invoke(factory, new object[] {
                 remote_address,
                 Via
             });
             this.factory = factory;
         }
         catch (System.Reflection.TargetInvocationException ex)
         {
             if (ex.InnerException != null)
             {
                 throw ex.InnerException;
             }
             else
             {
                 throw;
             }
         }
     }
 }
Beispiel #31
0
 void ExecuteOnProcessesByName(string ProcessName, ProcessDelegate func)
 {
     Process[] processes = Process.GetProcessesByName(ProcessName);
     foreach (var process in processes)
     {
         if (Process.GetCurrentProcess().Id == GetParentProcessId(process.Id))
         {
             func(process);
         }
     }
 }
Beispiel #32
0
        static void Main(string[] args)
        {
            ProcessDelegate process;

            WriteLine("Please enter a string:");
            process = new ProcessDelegate(myReadLine);
            string userInput = process();

            WriteLine($"You've input {userInput}");
            ReadKey();
        }
        public ArgumentOption(string name, string shortName, string description, bool isCaseSensitive, /*bool allowMultipleExecutions, */ List <ArgumentInternal> internalArguments, ProcessDelegate process)
        {
            Name            = name;
            ShortName       = shortName;
            Description     = description;
            IsCaseSensitive = isCaseSensitive;
//			AllowMultipleExecutions = allowMultipleExecutions;
            AllowMultipleExecutions = false;
            InternalArguments       = internalArguments;
            Process = process;
        }
Beispiel #34
0
        //returns a list of strings to report
        public List <string> ProcessGardens(ProcessDelegate processDelegate)
        {
            List <string> gardenReports = new List <string>();

            foreach (Garden garden in gardens)
            {
                gardenReports.Add(processDelegate(garden));
            }

            return(gardenReports);
        }
Beispiel #35
0
        //start all steps
        private void btnStart_Click(object sender, EventArgs e)
        {
            this.InitDgvRows();

            this.timGifAnimation.Enabled = true;
            this._CurrentStep            = 0;

            ProcessDelegate pdSteps = new ProcessDelegate(Process);

            pdSteps.BeginInvoke(null, null);
        }
        public NumericProcessor(object mandatoryArgument, object value, ProcessDelegate<decimal> processDelegate)
            : base(mandatoryArgument)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (processDelegate == null)
            {
                throw new ArgumentNullException("processDelegate");
            }

            _value = Convert.ToDecimal(value, CultureInfo.InvariantCulture); // will throw exception on mismatch
            _processDelegate = processDelegate;
        }
Beispiel #37
0
        public StringProcessor(object mandatoryArgument, object value, ProcessDelegate<string> processDelegate)
            : base(mandatoryArgument)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (processDelegate == null)
            {
                throw new ArgumentNullException("processDelegate");
            }

            _value = (string)value; // will throw exception on mismatch
            _processDelegate = processDelegate;
        }
Beispiel #38
0
 static void Main(string[] args)
 {
     ProcessDelegate process;
     Console.WriteLine("Enter 2 numbers separated with a comma:");
     string input = Console.ReadLine();
     int commaPos = input.IndexOf(',');
     double param1 = Convert.ToDouble(input.Substring(0, commaPos));
     double param2 = Convert.ToDouble(input.Substring(commaPos + 1,
                                      input.Length - commaPos - 1));
     Console.WriteLine("Enter M to multiply or D to divide:");
     input = Console.ReadLine();
     if (input == "M")
         process = new ProcessDelegate(Multiply);
     else
         process = new ProcessDelegate(Divide);
     Console.WriteLine("Result: {0}", process(param1, param2));
     Console.ReadKey();
 }
Beispiel #39
0
 public void StartServer(ProcessDelegate trace)
 {
     th = new Thread(new ThreadStart(runServer));
         th.IsBackground = true;
         th.Start();
         nd = new ProcessDelegate(trace);
         ArrayList al=new ArrayList();
         al.Add("int");
         al.Add("string");
         al.Add("int");
         al.Add("int");
         al.Add("string");
         al.Add("string");
         al.Add("int");
         al.Add("int");
         al.Add("int");
         KeyType.addType(111,al);
 }
Beispiel #40
0
 static void Main(string[] args)
 {
     ProcessDelegate process;
     Console.WriteLine("Enter 2 numbers separated with a comma:");
                        // Введите 2 числа, отделив их друг от друга запятой 
     string input = Console.ReadLine();
     int commaPos = input.IndexOf(',');
     double paraml = Convert.ToDouble(input.Substring(0, commaPos));
     double param2 = Convert.ToDouble(input.Substring(commaPos + 1,
         input.Length - commaPos - 1));
     Console.WriteLine("Enter M to multiply or D to divide:");
                        // Введите М, если хотите выполнить операцию умножения, 
                        // или D, если операцию деления 
     input = Console.ReadLine();
     if (input == "M")
         process = new ProcessDelegate(Multiply);
     else
         process = new ProcessDelegate(Divide);
     Console.WriteLine("Result: {0}", process(paraml, param2));
                        // Вывод результата 
     Console.ReadKey();
 }
Beispiel #41
0
        public void Process()
        {
            Log.Debug("ThreadExecutor", "[" + ThreadID + "] Processing ...");

            while (IsRunning)
            {
                if (ProcessEvent != null)
                {
                    Processing = true;
                    long StartTime = TCPManager.GetTimeStampMS();

                    try
                    {
                        ProcessEvent.Invoke(this);
                    }
                    catch (Exception e)
                    {
                        Log.Error("ThreadExecutor", e.ToString());
                    }

                    long Elapsed = TCPManager.GetTimeStampMS() - StartTime;

                    Processing = false;
                    ProcessEvent = null;

                    if(Elapsed < WaitTimeMS && IsRunning)
                        Thread.Sleep((int)(WaitTimeMS - Elapsed));
                }
                else if(IsRunning)
                    Thread.Sleep(WaitTimeMS);
            }

            Log.Debug("ThreadExecutor", "Process Stop : " + ThreadID);
        }
Beispiel #42
0
 public void SetProcess(ProcessDelegate Proc, int ExecuteCount)
 {
 }
Beispiel #43
0
 public static void AddProcess(ProcessDelegate Process, bool NewThread=false, int ExecuteCount=1)
 {
 }
Beispiel #44
0
        public void Start()
        {
            ProcessDelegate proc = new ProcessDelegate(DoStart);

            m_processInfo = new Syscalls.PROCESS_INFORMATION();
            CreateProcess(null, CommandLine, InheritHandles, CreationFlags, ref m_startupInfo, out m_processInfo);
            m_running = true;
            proc.BeginInvoke(null, null);
        }
Beispiel #45
0
		/// <summary>
		/// Overridden.  Invokes the initialize method on the event dispatch thread.
		/// </summary>
		/// <remarks>
		/// The handle of the canvas should exist at this point, so it is safe to call invoke.
		/// </remarks>
		protected override void OnCreateControl() {
			base.OnCreateControl ();

			//Force visible
			this.Visible = true;
			this.Refresh();

			//Necessary to invalidate the bounds because the state will be incorrect since
			//the message loop did not exist when the inpts were scheduled.
			this.canvas.Root.InvalidateFullBounds();
			this.canvas.Root.InvalidatePaint();

			this.processDelegate = new ProcessDelegate(Initialize);
			canvas.Invoke(processDelegate);
		}
 private void ProcessAsync(Simulation.Matrix_Worksheet matrixWS)
 {
     ProcessDelegate process = new ProcessDelegate(Process);
     process.BeginInvoke(matrixWS,null,null);
 }
 void ExecuteOnProcessesByName(string ProcessName , ProcessDelegate func)
 {
     try
     {
         Process[] processes = Process.GetProcessesByName(ProcessName);
         foreach (var p in processes)
             if (Process.GetCurrentProcess().Id == GetParrentProcessId(p.Id))
                 func(p);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #48
0
 /*метод, котоорый выполняет проход по всем дочерним процессам с заданым 
  *именем и выполняющий для этих процессов заданый делегатом метод*/
 void ExecuteOnProcessesByName(string ProcessName, ProcessDelegate func)
 {
     /*оплучаем список, запущенных в операционной системе процессов*/
     Process[] processes = Process.GetProcessesByName(ProcessName);
     foreach (var process in processes)
         /*если PID родительского процесса равен PID текущего процесса*/
         if(Process.GetCurrentProcess().Id == GetParentProcessId(process.Id))
             //запускаем метод
             func(process);
 }
Beispiel #49
0
 static void Main(string[] args)
 {
     Console.WriteLine("1)New object CupOfCoffe\n2)New object CupOfTea");
     ProcessDelegate process;
     int i;
     do
     {
         i=Convert.ToInt32(Console.ReadLine());
     } while (i<1 || i>2);
     switch (i)
     {
         case 1:
         {
             CupOfCoffee xCoffee = new CupOfCoffee();
             process = new ProcessDelegate(MyCoffe);
             process(xCoffee);
         }
             break;
         case 2:
         {
             CupOfTea xTea = new CupOfTea("White",100,"Цейлон");
             process = new ProcessDelegate(MyTea);
             process(xTea);
         }
             break;
     }
     Console.ReadKey();
 }