当前位置: 首页>>代码示例>>C#>>正文


C# Func.EndInvoke方法代码示例

本文整理汇总了C#中Func.EndInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# Func.EndInvoke方法的具体用法?C# Func.EndInvoke怎么用?C# Func.EndInvoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Func的用法示例。


在下文中一共展示了Func.EndInvoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ScanDouble

        static void ScanDouble()
        {
            // Delegates anlegen
            var dg1 = new Func<long, long, IEnumerable<long>>(mko.Algo.NumberTheory.PrimeFactors.scan);
            var dg2 = new Func<long, long, IEnumerable<long>>(mko.Algo.NumberTheory.PrimeFactors.scan);
            var dg3 = new Func<long, long, IEnumerable<long>>(mko.Algo.NumberTheory.PrimeFactors.scan);
            var dg4 = new Func<long, long, IEnumerable<long>>(mko.Algo.NumberTheory.PrimeFactors.scan);


            // Methoden asynchron mittels Delegates starten
            var ares1=  dg1.BeginInvoke(1, 2500000, null, null);
            var ares2=  dg2.BeginInvoke(2500001, 5000000, null, null);
            var ares3 = dg3.BeginInvoke(5000001, 75000000, null, null);
            var ares4 = dg4.BeginInvoke(7500001, 10000000, null, null);

            while (!ares1.IsCompleted && !ares2.IsCompleted && !ares3.IsCompleted && !ares4.IsCompleted)
            {
                Debug.Write(".");
                System.Threading.Thread.Sleep(200);
            }

            //ares1.AsyncWaitHandle.WaitOne();

            var res1 = dg1.EndInvoke(ares1);
            var res2 = dg2.EndInvoke(ares2);

        }
开发者ID:mk-prg-net,项目名称:CSharp45.Basics,代码行数:27,代码来源:Program.cs

示例2: apm

 /// AsynchronouseProngraingModel
 void apm()
 {
     before_work();
     var method = new Func<double>(() => { busy_work(); return 0; });
     method.BeginInvoke(ar =>
     {
         var result = method.EndInvoke(ar);// get return value
         this.BeginInvoke((Action)(() => { after_work(); }));
     }, null);
 }
开发者ID:n-n-n,项目名称:CsCodes,代码行数:11,代码来源:Form1.cs

示例3: ybpara

 /// <summary>异步传参数
 /// </summary>
 /// <param name="age"></param>
 public static void ybpara(int age)
 {
     //异步执行
     Func<people, string> FuncAsy = new Func<people, string>((pp) =>
     {
         return pp.Name;
     }
     );
     FuncAsy.BeginInvoke(new people("小李" + age, age), resual =>
     {
         //异步执行,从回调函数中获取返回结果
         Console.WriteLine(">>>>:{0}", FuncAsy.EndInvoke(resual));
         Console.WriteLine(">>>>:{0} end", age);
     }, null);
 }
开发者ID:zhuhuijun,项目名称:mydelete,代码行数:18,代码来源:Program.cs

示例4: yb

 /// <summary>异步
 /// </summary>
 /// <param name="age"></param>
 public static void yb(int age)
 {
     //异步执行
     Func<string> FuncAsy = new Func<string>(() =>
     {
         people tPeo = new people("异步小李", age);
         return tPeo.ToString();
     }
     );
     FuncAsy.BeginInvoke(resual =>
     {
         //异步执行,从回调函数中获取返回结果
         Console.WriteLine(">>>>:{0}", FuncAsy.EndInvoke(resual));
         Console.WriteLine(">>>>:{0} end", age);
     }, null);
 }
开发者ID:zhuhuijun,项目名称:mydelete,代码行数:19,代码来源:Program.cs

示例5: LoadAsync

 public static void LoadAsync(string filename, Action<IStorableContent, Exception> loadingCompletedCallback) {
   if (instance == null) throw new InvalidOperationException("ContentManager is not initialized.");
   var func = new Func<string, IStorableContent>(instance.LoadContent);
   func.BeginInvoke(filename, delegate(IAsyncResult result) {
     Exception error = null;
     IStorableContent content = null;
     try {
       content = func.EndInvoke(result);
       content.Filename = filename;
     }
     catch (Exception ex) {
       error = ex;
     }
     loadingCompletedCallback(content, error);
   }, null);
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:16,代码来源:ContentManager.cs

示例6: Main

        static void Main(string[] args)
        {
            Func<int, int, int> additionDel = new Func<int, int, int>(Addition);
            int ret = additionDel.Invoke(1, 2);
            Console.WriteLine("From Sync invoke " + ret);
            object state = new Object();
            IAsyncResult _asyncresult = additionDel.BeginInvoke(1,2,null, null);
            //calling thread blocks until endInvokecompletes
            ret= additionDel.EndInvoke(_asyncresult);
            Console.WriteLine("From Aynsc EndInvoke " + ret);

             _asyncresult = additionDel.BeginInvoke(1, 2, new AsyncCallback(PrintCallBack), null);
            // ret = additionDel.EndInvoke(_asyncresult);
            // Console.WriteLine("From Aynsc EndInvoke On asyncCallback" + ret);

             Thread.Sleep(5000);

        }
开发者ID:edwardt,项目名称:KeyConcepts,代码行数:18,代码来源:Program.cs

示例7: button4_Click

 //ThreadPoolで非同期処理実施し戻り値が使用するパターン
 //APM(Asynchronous Programming Model)
 private void button4_Click(object sender, EventArgs e)
 {
     this.button4.Enabled = false;
     var ayncMethod = new Func<string>(() =>
     {
         Thread.Sleep(3000);
         return "3秒経過";
     });
     ayncMethod.BeginInvoke(ar => 
     {
         var res = ayncMethod.EndInvoke(ar);
         this.BeginInvoke((Action)(()=>
         {
             this.button4.Enabled = true;
             this.button4.Text = res;
         }));
     },null);
 }
开发者ID:FirstProgramingStudy301-B,项目名称:another,代码行数:20,代码来源:Form1.cs

示例8: RefreshAsync

 public void RefreshAsync(Action<Exception> exceptionCallback) {
   var call = new Func<Exception>(delegate() {
     try {
       Refresh();
     }
     catch (Exception ex) {
       return ex;
     }
     return null;
   });
   call.BeginInvoke(delegate(IAsyncResult result) {
     Exception ex = call.EndInvoke(result);
     if (ex != null) exceptionCallback(ex);
   }, null);
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:15,代码来源:HiveClient.cs

示例9: StoreAsync

 public static void StoreAsync(Action<Exception> exceptionCallback, IHiveItem item, CancellationToken cancellationToken) {
   var call = new Func<Exception>(delegate() {
     try {
       Store(item, cancellationToken);
     }
     catch (Exception ex) {
       return ex;
     }
     return null;
   });
   call.BeginInvoke(delegate(IAsyncResult result) {
     Exception ex = call.EndInvoke(result);
     if (ex != null) exceptionCallback(ex);
   }, null);
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:15,代码来源:HiveClient.cs

示例10: CreateEmbroidery

        public void CreateEmbroidery(Preview preview, string imageName, int coefficient, int cellsCount, DColor[] palette, char[] symbols, DColor symbolColor, Embroidery.GridType gridType)
        {

            BitmapSource bitmapSource = null;

            try
            {
                DBitmap _imageFromFile = new DBitmap(imageName);

                Func<DBitmap, DBitmap> getCopyBitmap = new Func<DBitmap, DBitmap>(GetCopyOfBitmap);
                IAsyncResult getCopyBitmapResult = getCopyBitmap.BeginInvoke(_imageFromFile, null, null);
                DBitmap inputImage = getCopyBitmap.EndInvoke(getCopyBitmapResult);

                Embroidery.EmbroideryCreatorServiceClient wcf_service = new Embroidery.EmbroideryCreatorServiceClient();

                Func<DBitmap, int, int, DColor[], char[], DColor, Embroidery.GridType, DBitmap> getEmbroidery = new Func<DBitmap, int, int, DColor[], char[], DColor, Embroidery.GridType, DBitmap>(wcf_service.GetEmbroidery);
                IAsyncResult getEmbroideryResult = getEmbroidery.BeginInvoke(inputImage, coefficient, cellsCount, palette, symbols, DColor.Black, gridType, null, null);
                DBitmap resultImage = getEmbroidery.EndInvoke(getEmbroideryResult);


                if (resultImage == null)
                {
                    MessageBox.Show("Some error occured on the server");
                    //HideLoading();
                    return;
                }

                bitmapSource = GetBitmapSource(resultImage);
            }
            catch (OutOfMemoryException ex)
            {
                MessageBox.Show("Sorry, but image is too large :(");
                //HideLoading();
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Some exception was occured. Message: " + ex.Message);
                //HideLoading();
                return;
            }

            bitmapSource.Freeze();

            preview.Dispatcher.BeginInvoke(new Action(() =>
                {
                    preview.loadingPanel.Visibility = System.Windows.Visibility.Collapsed;
                    preview.previewImage.Source = bitmapSource;
                }),
                System.Windows.Threading.DispatcherPriority.Normal);
           

        }
开发者ID:nsvova,项目名称:Embroidery-NS-Vova,代码行数:53,代码来源:MainWindow.xaml.cs

示例11: TimeoutTest

 public void TimeoutTest()
 {
     // Arrange.
     var func = new Func<ProcessExecutionResult>(() => ProcessRunner.RunProcess("cmd.exe", PauseArguments, Timeout));
     // Act.
     var result = func.BeginInvoke((a) => { }, null);
     result.AsyncWaitHandle.WaitOne(Timeout + AdditionalTimeout);
     // Assert.
     if (result.IsCompleted)
     {
         func.EndInvoke(result);
     }
 }
开发者ID:killfactory,项目名称:ExecProcessRunner,代码行数:13,代码来源:TimeoutTests.cs

示例12: Execute

 private void Execute(Func<string> worker, Action<string> completeMethod)
 {
     if (_handleCreated)
         worker.BeginInvoke(ar =>
         {
             var result = worker.EndInvoke(ar);
             BeginInvoke(completeMethod, result);
         }, null);
     else
         lock (_queuedExecutions)
             _queuedExecutions.Enqueue(new Tuple<Func<string>, Action<string>>(worker, completeMethod));
 }
开发者ID:sat1582,项目名称:CODEFramework,代码行数:12,代码来源:TestServiceHost.cs

示例13: IsCompletedTest

        /// <summary>
        /// 本方法 通过 启用1个异步处理.
        /// 
        /// 然后通过 周期的去 查询 IsCompleted 。
        /// 来判断异步处理是否完成.
        /// 
        /// </summary>
        public static void IsCompletedTest()
        {

            Console.WriteLine("==#{0}主线程处理开始:{1}",
                            Thread.CurrentThread.ManagedThreadId,
                            DateTime.Now.ToString("hh:mm:ss"));

            // 定义方法.
            var func = new Func<int, int, int>(AsyncOperation);

            // 异步调用.
            var result = func.BeginInvoke(100, 200, null, null);



            Thread.Sleep(1000);

            Console.WriteLine("==#{0}主线程处理结束:{1}",
                            Thread.CurrentThread.ManagedThreadId,
                            DateTime.Now.ToString("hh:mm:ss"));


            while (!result.IsCompleted)
            {
                Console.WriteLine("==#{0}主线程等待异步处理执行完毕:{1}",
                                Thread.CurrentThread.ManagedThreadId,
                                DateTime.Now.ToString("hh:mm:ss"));
                Thread.Sleep(500);
            }

            int r = func.EndInvoke(result);

            Console.WriteLine("==#{0}主线程获取的 异步操作结果:{1}",
                Thread.CurrentThread.ManagedThreadId,
                r);

            Console.WriteLine();
        }
开发者ID:mahuidong,项目名称:my-csharp-sample,代码行数:45,代码来源:TestAsync.cs

示例14: Invoke

 public object Invoke(Delegate method, object[] args)
 {
     sawInvoke = true;
     action = () => method.DynamicInvoke(args);
     return action.EndInvoke(action.BeginInvoke(null, null));
 }
开发者ID:GotAudio,项目名称:ModbusExcel,代码行数:6,代码来源:CallbackContext.UnitTests.cs

示例15: LoadData

 /// <summary>
 /// 加载数据
 /// </summary>
 void LoadData()
 {
     if (IsLoading) return;
     this.IsLoading = true;
     var client = new WebService.WeatherWebServiceSoapClient();
     var func = new Func<DataSet>(client.getSupportDataSet);
     func.BeginInvoke(ar =>
     {
         var ds = func.EndInvoke(ar);
         InvokeOnUIDispatcher(new Action(() =>
         {
             this.InitZoneFromDataSet(ds);
             //this.CurrentZoneID = this.CurrentArea.ZoneID;
             //this.CurrentAreaID = this.CurrentArea.ID;
             this.IsLoading = false;
         }));
     }, null);
 }
开发者ID:binbin0915,项目名称:binbindotnetproject,代码行数:21,代码来源:CityViewModel.cs


注:本文中的Func.EndInvoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。