本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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));
}
示例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();
}
示例14: Invoke
public object Invoke(Delegate method, object[] args)
{
sawInvoke = true;
action = () => method.DynamicInvoke(args);
return action.EndInvoke(action.BeginInvoke(null, null));
}
示例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);
}